twindow.cpp
来自「从FFMPEG转换而来的H264解码程序,VC下编译..」· C++ 代码 · 共 1,109 行 · 第 1/3 页
CPP
1,109 行
/*
* Copyright (c) 2002-2006 Milan Cutka
* anchors inspired by Visual Component Library by Borland
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "stdafx.h"
#include "Twindow.h"
#include "Ttranslate.h"
#include "IffdshowBase.h"
#include "ffdshow_constants.h"
#include "Crect.h"
#include "ffdebug.h"
#include "IffdshowParamsEnum.h"
#include "TdialogSettings.h"
#include "reg.h"
//=================================== Twindow ==================================
Twindow::Twindow(IffdshowBase *Ideci):
tr(NULL),
wndEnabled(true),
isSetWindowText(false),
bindsCheckbox(NULL),bindsHtrack(NULL),bindsVtrack(NULL),bindsRadiobutton(NULL),bindsEditInt(NULL),bindsEditReal(NULL),bindsCombobox(NULL),bindsButton(NULL),
red(NULL),
filterMode(NULL)
{
if (Ideci)
setDeci(Ideci);
else
{
deci=NULL;
hi=NULL;
}
cbxTextBuf=NULL;cbxTextBufLen=0;
hhint=NULL;
}
Twindow::~Twindow()
{
// if (hhint) DestroyWindow(hhint);
if (cbxTextBuf) free(cbxTextBuf);
if (tr) tr->release();
}
void Twindow::setDeci(IffdshowBase *Ideci)
{
deci=Ideci;
deci->getTranslator(&tr);
deci->getConfig(&config);
filterMode=cfgGet(IDFF_filterMode);
hi=(HINSTANCE)deci->getInstance2();
}
Twidget* Twindow::createDlgItem(int id,HWND h)
{
TtrackBarsMap::const_iterator t=bindTrackbarsMap.find(id);
if (t!=bindTrackbarsMap.end())
return new TwidgetSubclassTbr(h,this,t->second);
else
{
TcheckboxesMap::const_iterator t=bindCheckboxesMap.find(id);
if (t!=bindCheckboxesMap.end())
return new TwidgetSubclassChb(h,this,t->second);
else
return new TwindowWidget(h,this);
}
}
void Twindow::setHWND(HWND Im_hwnd,int IdialogId)
{
m_hwnd=Im_hwnd;
if (IdialogId) dialogId=IdialogId;
THWNDs wnds;getChildWindows(m_hwnd,wnds);
for (THWNDs::const_iterator wnd=wnds.begin();wnd!=wnds.end();wnd++)
{
Twidget *dlgitem=createDlgItem(getId(*wnd),*wnd);
if (tr->translateMode && dialogId!=IDD_PROPSEDIT)
{
char_t className[256];
GetClassName(*wnd,className,256);
if (stricmp(className,_l("STATIC"))==0 || stricmp(className,_l("BUTTON"))==0 || stricmp(className,_l("ComboBox"))==0 || stricmp(className,_l("syslistview32"))==0)
{
if (stricmp(className,_l("STATIC"))==0)
SetWindowLong(*wnd,GWL_STYLE,GetWindowLong(*wnd,GWL_STYLE)|SS_NOTIFY);
else if (stricmp(className,_l("BUTTON"))==0)
{
SetWindowLong(*wnd,GWL_STYLE,GetWindowLong(*wnd,GWL_STYLE)|BS_NOTIFY);
if ((GetWindowLong(*wnd,GWL_STYLE)&BS_GROUPBOX)==BS_GROUPBOX)
{
char_t windowtext[256];
GetWindowText(*wnd,windowtext,256);
if (windowtext[0]!='\0')
{
SendMessage(*wnd,BM_SETSTYLE,BS_PUSHBUTTON,1);
RECT r;
GetWindowRect(*wnd,&r);
SetWindowPos(*wnd,NULL,0,0,r.right-r.left,15,SWP_NOMOVE|SWP_NOZORDER);
}
}
}
EnableWindow(*wnd,TRUE);
dlgitem->allowOwnProc(); //setDlgItemProc(*wnd,translateProc);
}
}
}
Twidget *dlgitem=createDlgItem(0,m_hwnd);
//SetWindowLong(m_hwnd,GWL_USERDATA,LONG(createDlgItem()));
if (tr->translateMode)
dlgitem->allowOwnProc();// setDlgItemProc(m_hwnd,translateProc);
}
const char_t* Twindow::_(int item)
{
return tr->translate(m_hwnd,dialogId,item,NULL);
}
const char_t* Twindow::_(int id,const char_t *s,bool addcbx)
{
if (addcbx && tr->translateMode && s[0])
{
strings &list=translateCbxs[id];
if (!isIn(list,ffstring(s)))
list.push_back(s);
}
return tr->translate(s);
}
HMENU Twindow::_(HMENU hmn)
{
if (hmn)
{
int cnt=GetMenuItemCount(hmn);
for (int i=0;i<cnt;i++)
{
MENUITEMINFO mii;memset(&mii,0,sizeof(mii));
mii.cbSize=sizeof(mii);
mii.fMask=MIIM_STRING;
char_t capt[256];
mii.dwTypeData=capt;
mii.cch=255;
GetMenuItemInfo(hmn,i,TRUE,&mii);
strcpy(mii.dwTypeData,_(-dialogId,mii.dwTypeData));
SetMenuItemInfo(hmn,i,TRUE,&mii);
}
}
return hmn;
}
void Twindow::translate(void)
{
tr->translate(m_hwnd,dialogId);
/*
HFONT hf=(HFONT)SendMessage(m_hwnd,WM_GETFONT,NULL,NULL);
LOGFONT lf;
GetObject(hf,sizeof(lf),&lf);
lf.lfCharSet=RUSSIAN_CHARSET;
HFONT hf2=CreateFontIndirect(&lf);
THWNDs wnds;
getChildWindows(m_hwnd,wnds);
for (THWNDs::const_iterator w=wnds.begin();w!=wnds.end();w++)
SendMessage(*w,WM_SETFONT,(WPARAM)hf2,TRUE);
SendMessage(m_hwnd,WM_SETFONT,(WPARAM)hf2,TRUE);
*/
}
void Twindow::enable2(HWND hwnd,BOOL is,bool uncheck)
{
if (tr->translateMode) return;
EnableWindow(hwnd,is);
if (!is && uncheck)
{
char_t name[256];
if (GetClassName(hwnd,name,255) && stricmp(name,_l("button"))==0)
{
ownSetCheck=true;
SendMessage(hwnd,BM_SETCHECK,BST_UNCHECKED,0);
ownSetCheck=false;
}
}
}
template<class T> static T strto(const char_t *s,char_t **e);
template<> double strto(const char_t *s,char_t **e) {return strtod(s,e);}
template<> int strto(const char_t *s,char_t **e) {return strtol(s,e,10);}
template<class T> bool Twindow::eval(const char_t *pomS,T min,T max,int *val,T mult,bool dolimit)
{
if (pomS[0]=='\0') return false;
char_t *stop=NULL;
T x=strto<T>(pomS,&stop);
if (*stop) return false;
if (!isIn(x,min,max))
if (!dolimit)
return false;
else
x=limit(x,min,max);
if (val) *val=int(x*mult); //round?
return true;
}
template bool Twindow::eval(const char_t *pomS,int min,int max,int *val,int mult,bool dolimit);
template bool Twindow::eval(const char_t *pomS,double min,double max,int *val,double mult,bool dolimit);
bool Twindow::eval(HWND hed,int min,int max,int *val,int mult,bool limit)
{
char_t pomS[256];
GetWindowText(hed,pomS,255);
return eval(pomS,min,max,val,mult,limit);
}
bool Twindow::eval(HWND hed,double min,double max,int *val,double mult,bool limit)
{
char_t pomS[256];
GetWindowText(hed,pomS,255);
return eval(pomS,min,max,val,mult,limit);
}
bool Twindow::inputString(const char_t *capt,const char_t *query,char_t *str,size_t len)
{
TdlgInputString dlg(capt,query,str,len,deci);
return dlg.execute(m_hwnd);
}
void Twindow::ListView_AddCol(HWND hlv,int &ncol,int w,const char_t *txt,bool right)
{
LVCOLUMN lvc;
lvc.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvc.iSubItem=ncol;
lvc.pszText=LPTSTR(txt);
lvc.cx=w;
lvc.fmt=(right)?LVCFMT_RIGHT:LVCFMT_LEFT;
ListView_InsertColumn(hlv,ncol,&lvc);
ncol++;
}
LPARAM Twindow::lvGetItemParam(int id,int i)
{
LVITEM lvi;
lvi.mask=LVIF_PARAM;
lvi.iItem=i;
lvi.iSubItem=0;
ListView_GetItem(GetDlgItem(m_hwnd,id),&lvi);
return lvi.lParam;
}
void Twindow::lvSwapItems(int id,int i1,int i2)
{
HWND hlv=GetDlgItem(m_hwnd,id);
LVITEM lvi1;char_t text1[256];int check1;
lvi1.mask=LVIF_PARAM|LVIF_STATE|LVIF_TEXT;
lvi1.iItem=i1;lvi1.iSubItem=0;
lvi1.pszText=text1;lvi1.cchTextMax=256;
ListView_GetItem(hlv,&lvi1);
check1=ListView_GetCheckState(hlv,i1);
LVITEM lvi2;char_t text2[256];int check2;
lvi2.mask=LVIF_PARAM|LVIF_STATE|LVIF_TEXT;
lvi2.iItem=i2;lvi2.iSubItem=0;
lvi2.pszText=text2;lvi2.cchTextMax=256;
ListView_GetItem(hlv,&lvi2);
check2=ListView_GetCheckState(hlv,i2);
std::swap(lvi1.iItem,lvi2.iItem);
ListView_SetItem(hlv,&lvi1);ListView_SetCheckState(hlv,i1,check2);
ListView_SetItem(hlv,&lvi2);ListView_SetCheckState(hlv,i2,check1);
lvSetSelItem(id,i2);
ListView_EnsureVisible(hlv,i2,FALSE);
}
void Twindow::cbxTranslate(int id,const char_t **list)
{
int sel=cbxGetCurSel(id);
cbxClear(id);
for (int i=0;list[i];i++)
cbxAdd(id,_(id,list[i]));
cbxSetCurSel(id,sel);
}
void Twindow::tbrSet(int id,int val,int lblId,const char_t *Icapt,float div)
{
SendDlgItemMessage(m_hwnd,id,TBM_SETPOS,TRUE,val);
if (lblId)
{
const char_t *capt=((Icapt && Icapt[0])?Icapt:_(lblId));
char_t s[256];
if (div==0)
tsprintf(s,_l("%s %i"),capt,val);
else
tsprintf(s,_l("%s %g"),capt,float(val/div));
setDlgItemText(m_hwnd,lblId,s);
}
}
void Twindow::tbrSetRange(int id,int min,int max,int step,bool largethumb)
{
SendDlgItemMessage(m_hwnd,id,TBM_SETRANGEMIN,TRUE,min);
SendDlgItemMessage(m_hwnd,id,TBM_SETRANGEMAX,TRUE,max);
SendDlgItemMessage(m_hwnd,id,TBM_SETLINESIZE,0,1);
SendDlgItemMessage(m_hwnd,id,TBM_SETPAGESIZE,0,step?step:std::max(1,(max-min)/15));
if (largethumb)
{
HWND hcbx=GetDlgItem(m_hwnd,id);
SetWindowLong(hcbx,GWL_STYLE,GetWindowLong(hcbx,GWL_STYLE)|TBS_FIXEDLENGTH);
RECT r;
GetWindowRect(hcbx,&r);
if (GetWindowStyle(hcbx)&TBS_VERT)
SendMessage(hcbx,TBM_SETTHUMBLENGTH,r.right-r.left-2,0);
else
SendMessage(hcbx,TBM_SETTHUMBLENGTH,r.bottom-r.top-2,0);
}
}
int Twindow::cfgGet(unsigned int i)
{
return deci->getParam2(i);
}
void Twindow::cfgGet(unsigned int i,char_t *buf,size_t buflen)
{
deci->getParamStr(i,buf,buflen);
}
const char_t* Twindow::cfgGetStr(unsigned int i)
{
return deci->getParamStr2(i);
}
void Twindow::cfgSet(unsigned int i,int val)
{
deci->putParam(i,val);
}
void Twindow::cfgSet(unsigned int i,const char_t *val)
{
deci->putParamStr(i,val);
}
void Twindow::setText(int id,const char_t *fmt,...)
{
char_t s[1024];
va_list args;
va_start(args,fmt);
int len=_vsnprintf(s,1024,fmt,args);
va_end(args);
if (len<-1) return;
s[1023]='\0';
setDlgItemText(m_hwnd,id,s);
}
void Twindow::msg(const char_t *text,const char_t *capt)
{
MessageBox(m_hwnd,text,capt,MB_ICONINFORMATION|MB_OK);
}
void Twindow::err(const char_t *text,const char_t *capt)
{
MessageBox(m_hwnd,text,capt?capt:_(-dialogId,_l("Error")),MB_ICONERROR|MB_OK);
}
void Twindow::insertSeparator(HMENU hm,int &ord)
{
MENUITEMINFO mii;
mii.cbSize=sizeof(mii);
mii.fMask=MIIM_TYPE;
mii.fType=MFT_SEPARATOR;
InsertMenuItem(hm,ord++,TRUE,&mii);
}
void Twindow::insertSubmenu(HMENU hm,int &ord,const char_t *caption,HMENU subMenu)
{
MENUITEMINFO mii;
mii.cbSize=sizeof(mii);
mii.fMask=MIIM_TYPE|MIIM_SUBMENU;
mii.fType=MFT_STRING;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?