📄 searchparamswnd.cpp
字号:
GetDlgItem(IDC_MSTATIC3)->MoveWindow(rcClient.left + m_rcNameLbl.left, rcClient.top + m_rcNameLbl.top, m_rcNameLbl.Width(), m_rcNameLbl.Height());
m_ctlName.MoveWindow(rcClient.left + m_rcName.left, rcClient.top + m_rcName.top, m_rcName.Width(), m_rcName.Height());
m_ctlUnicode.MoveWindow(rcClient.left + m_rcUnicode.left, rcClient.top + m_rcUnicode.top, m_rcUnicode.Width(), m_rcUnicode.Height());
GetDlgItem(IDC_DD)->MoveWindow(rcClient.left + m_rcDropDownArrow.left, rcClient.top + m_rcDropDownArrow.top, m_rcDropDownArrow.Width(), m_rcDropDownArrow.Height());
GetDlgItem(IDC_MSTATIC7)->MoveWindow(rcClient.left + m_rcFileTypeLbl.left, rcClient.top + m_rcFileTypeLbl.top, m_rcFileTypeLbl.Width(), m_rcFileTypeLbl.Height());
m_ctlFileType.MoveWindow(rcClient.left + m_rcFileType.left, rcClient.top + m_rcFileType.top, m_rcFileType.Width(), m_rcFileType.Height());
GetDlgItem(IDC_SEARCH_RESET)->MoveWindow(rcClient.left + m_rcReset.left, rcClient.top + m_rcReset.top, m_rcReset.Width(), m_rcReset.Height());
GetDlgItem(IDC_METH)->MoveWindow(rcClient.left + m_rcMethodLbl.left, rcClient.top + m_rcMethodLbl.top, m_rcMethodLbl.Width(), m_rcMethodLbl.Height());
m_ctlMethod.MoveWindow(rcClient.left + m_rcMethod.left, rcClient.top + m_rcMethod.top, m_rcMethod.Width(), m_rcMethod.Height());
m_ctlStart.MoveWindow(rcClient.left + m_rcStart.left, rcClient.top + m_rcStart.top, m_rcStart.Width(), m_rcStart.Height());
m_ctlMore.MoveWindow(rcClient.left + m_rcMore.left, rcClient.top + m_rcMore.top, m_rcMore.Width(), m_rcMore.Height());
m_ctlCancel.MoveWindow(rcClient.left + m_rcCancel.left, rcClient.top + m_rcCancel.top, m_rcCancel.Width(), m_rcCancel.Height());
int iWidthOpts = rcClient.right - (rcClient.left + m_rcOpts.left);
m_ctlOpts.MoveWindow(rcClient.left + m_rcOpts.left, rcClient.top + m_rcOpts.top, iWidthOpts, m_rcOpts.Height());
CRect rcOptsClnt;
m_ctlOpts.GetClientRect(&rcOptsClnt);
m_ctlOpts.SetColumnWidth(0, LVSCW_AUTOSIZE);
m_ctlOpts.SetColumnWidth(1, rcOptsClnt.Width() - m_ctlOpts.GetColumnWidth(0));
m_ctlOpts.ModifyStyle(0, LVS_NOCOLUMNHEADER);
}
else if (cx < MIN_HORZ_WIDTH)
{
CRect rcClient;
GetClientRect(&rcClient);
CalcInsideRect(rcClient, FALSE);
int y = rcClient.top;
CRect rcNameLbl;
GetDlgItem(IDC_MSTATIC3)->GetWindowRect(&rcNameLbl);
ScreenToClient(&rcNameLbl);
GetDlgItem(IDC_MSTATIC3)->MoveWindow(rcClient.left, y, rcNameLbl.Width(), rcNameLbl.Height());
y += rcNameLbl.Height() + 2;
CRect rcName;
m_ctlName.GetWindowRect(&rcName);
ScreenToClient(&rcName);
CRect rcDropDownArrow;
GetDlgItem(IDC_DD)->GetWindowRect(&rcDropDownArrow);
ScreenToClient(&rcDropDownArrow);
int iNameWidth = rcClient.Width() - 4 - rcDropDownArrow.Width();
m_ctlName.MoveWindow(rcClient.left, y, iNameWidth, rcName.Height());
GetDlgItem(IDC_DD)->MoveWindow(rcClient.left + iNameWidth + 4, y, rcDropDownArrow.Width(), rcDropDownArrow.Height());
y += rcName.Height() + 2;
CRect rcUnicode;
m_ctlUnicode.GetWindowRect(&rcUnicode);
ScreenToClient(&rcUnicode);
m_ctlUnicode.MoveWindow(rcClient.left, y, rcClient.Width(), rcUnicode.Height());
y += rcUnicode.Height() + 8;
CRect rcFileTypeLbl;
GetDlgItem(IDC_MSTATIC7)->GetWindowRect(&rcFileTypeLbl);
ScreenToClient(&rcFileTypeLbl);
GetDlgItem(IDC_MSTATIC7)->MoveWindow(rcClient.left, y, rcFileTypeLbl.Width(), rcFileTypeLbl.Height());
y += rcFileTypeLbl.Height() + 2;
CRect rcFileType;
m_ctlFileType.GetWindowRect(&rcFileType);
ScreenToClient(rcFileType);
m_ctlFileType.MoveWindow(rcClient.left, y, rcFileType.Width(), rcFileType.Height());
CRect rcReset;
GetDlgItem(IDC_SEARCH_RESET)->GetWindowRect(&rcReset);
ScreenToClient(&rcReset);
GetDlgItem(IDC_SEARCH_RESET)->MoveWindow(rcClient.left + rcFileType.Width() + 8, y, rcReset.Width(), rcReset.Height());
y += rcFileType.Height() + 8;
CRect rcMethodLbl;
GetDlgItem(IDC_METH)->GetWindowRect(&rcMethodLbl);
ScreenToClient(&rcMethodLbl);
GetDlgItem(IDC_METH)->MoveWindow(rcClient.left, y, rcMethodLbl.Width(), rcMethodLbl.Height());
y += rcMethodLbl.Height() + 2;
CRect rcMethod;
m_ctlMethod.GetWindowRect(&rcMethod);
ScreenToClient(rcMethod);
m_ctlMethod.MoveWindow(rcClient.left, y, rcMethod.Width(), rcMethod.Height());
y += rcMethod.Height() + 8;
m_ctlStart.MoveWindow(rcClient.left, y, m_rcStart.Width(), m_rcStart.Height());
m_ctlMore.MoveWindow(rcClient.left + m_rcStart.Width() + 4, y, m_rcMore.Width(), m_rcMore.Height());
y += m_rcStart.Height() + 4;
m_ctlCancel.MoveWindow(rcClient.left, y, m_rcCancel.Width(), m_rcCancel.Height());
y += m_rcStart.Height() + 4;
int iOptsHeight = rcClient.bottom - y - 2;
m_ctlOpts.MoveWindow(rcClient.left, y, rcClient.Width(), iOptsHeight);
CRect rcOptsClnt;
m_ctlOpts.GetClientRect(&rcOptsClnt);
m_ctlOpts.SetColumnWidth(1, rcOptsClnt.Width() - m_ctlOpts.GetColumnWidth(0));
y += iOptsHeight + 4;
m_ctlOpts.ModifyStyle(LVS_NOCOLUMNHEADER, 0);
}
}
void CSearchParamsWnd::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
// Disable MFC's command routing by not passing the process flow to base class
}
void CSearchParamsWnd::UpdateControls()
{
int iMethod = m_ctlMethod.GetCurSel();
if (iMethod != CB_ERR)
{
if (iMethod != thePrefs.GetSearchMethod())
{
if (iMethod == SearchTypeKademlia)
OnEnChangeName();
else if (iMethod == SearchTypeEd2kServer && m_searchdlg->IsLocalSearchRunning())
m_ctlStart.EnableWindow(FALSE);
else if (iMethod == SearchTypeEd2kGlobal && m_searchdlg->IsGlobalSearchRunning())
m_ctlStart.EnableWindow(FALSE);
thePrefs.SetSearchMethod(iMethod);
}
}
m_ctlOpts.SetItemData(orAvailability, (iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orExtension, (iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orCompleteSources, (iMethod==SearchTypeKademlia || iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orCodec, (iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orBitrate, (iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orLength, (iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orTitle, (iMethod==SearchTypeEd2kServer || iMethod==SearchTypeEd2kGlobal || iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orAlbum, (iMethod==SearchTypeEd2kServer || iMethod==SearchTypeEd2kGlobal || iMethod==SearchTypeFileDonkey) ? 1 : 0);
m_ctlOpts.SetItemData(orArtist, (iMethod==SearchTypeEd2kServer || iMethod==SearchTypeEd2kGlobal || iMethod==SearchTypeFileDonkey) ? 1 : 0);
}
void CSearchParamsWnd::SetAllIcons()
{
CImageList iml;
iml.Create(16,16,theApp.m_iDfltImageListColorFlags|ILC_MASK,0,1);
iml.SetBkColor(CLR_NONE);
iml.Add(CTempIconLoader(_T("SearchMethod_SERVER"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_GLOBAL"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_KADEMLIA"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_FILEDONKEY"), 16, 16));
m_ctlMethod.SetImageList(&iml);
m_imlSearchMethods.DeleteImageList();
m_imlSearchMethods.Attach(iml.Detach());
iml.Create(16,16,theApp.m_iDfltImageListColorFlags|ILC_MASK,0,1);
iml.SetBkColor(CLR_NONE);
iml.Add(CTempIconLoader(_T("SearchFileType_Any"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchFileType_Archive"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchFileType_Audio"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchFileType_CDImage"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchFileType_Picture"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchFileType_Program"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchFileType_Video"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchFileType_Document"), 16, 16));
m_ctlFileType.SetImageList(&iml);
m_imlFileType.DeleteImageList();
m_imlFileType.Attach(iml.Detach());
}
void CSearchParamsWnd::OnDestroy()
{
CDialogBar::OnDestroy();
m_imlSearchMethods.DeleteImageList();
m_imlFileType.DeleteImageList();
}
void CSearchParamsWnd::OnSysColorChange()
{
CDialogBar::OnSysColorChange();
SetAllIcons();
}
void CSearchParamsWnd::InitMethodsCtrl()
{
int iMethod = m_ctlMethod.GetCurSel();
m_ctlMethod.ResetContent();
VERIFY( m_ctlMethod.AddItem(GetResString(IDS_SERVER), 0) == SearchTypeEd2kServer );
VERIFY( m_ctlMethod.AddItem(GetResString(IDS_GLOBALSEARCH), 1) == SearchTypeEd2kGlobal );
VERIFY( m_ctlMethod.AddItem(GetResString(IDS_KADEMLIA) + _T(" ") + GetResString(IDS_NETWORK), 2) == SearchTypeKademlia );
VERIFY( m_ctlMethod.AddItem(_T("VeryCD (Web)"), 1) == SearchTypeVeryCD ); //VeryCD
VERIFY( m_ctlMethod.AddItem(_T("FileDonkey (Web)"), 3) == SearchTypeFileDonkey );
UpdateHorzExtent(m_ctlMethod, 16); // adjust dropped width to ensure all strings are fully visible
m_ctlMethod.SetCurSel(iMethod != CB_ERR ? iMethod : SearchTypeEd2kServer);
}
class SFileTypeCbEntry
{
public:
SFileTypeCbEntry(const CString& strLabel, LPCSTR pszItemData, int iImage) {
m_strLabel = strLabel;
m_pszItemData = pszItemData;
m_iImage = iImage;
}
operator<(const SFileTypeCbEntry& e) const {
return (m_strLabel.Compare(e.m_strLabel) < 0);
}
CString m_strLabel;
LPCSTR m_pszItemData;
int m_iImage;
};
void CSearchParamsWnd::InitFileTypesCtrl()
{
// get current selected entry by value (language independent)
CStringA strCurSelFileType;
int iItem = m_ctlFileType.GetCurSel();
if (iItem != CB_ERR)
{
LPCSTR pszED2KFileType = (LPCSTR)m_ctlFileType.GetItemDataPtr(iItem);
ASSERT( pszED2KFileType != NULL );
strCurSelFileType = pszED2KFileType;
}
m_ctlFileType.ResetContent();
// create temp. list of new entries (language dependent)
std::list<SFileTypeCbEntry> lstFileTypeCbEntries;
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_ANY), "", 0));
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_ARC), ED2KFTSTR_ARCHIVE, 1));
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_AUDIO), ED2KFTSTR_AUDIO, 2));
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_CDIMG), ED2KFTSTR_CDIMAGE, 3));
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_PICS), ED2KFTSTR_IMAGE, 4));
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_PRG), ED2KFTSTR_PROGRAM, 5));
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_VIDEO), ED2KFTSTR_VIDEO, 6));
lstFileTypeCbEntries.push_back(SFileTypeCbEntry(GetResString(IDS_SEARCH_DOC), ED2KFTSTR_DOCUMENT, 7));
// sort list with current language locale
lstFileTypeCbEntries.sort();
// fill combobox control with already sorted list
std::list<SFileTypeCbEntry>::const_iterator it;
for (it = lstFileTypeCbEntries.begin(); it != lstFileTypeCbEntries.end(); it++)
{
int iItem;
if ((iItem = m_ctlFileType.AddItem((*it).m_strLabel, (*it).m_iImage)) != CB_ERR)
m_ctlFileType.SetItemData(iItem, (DWORD_PTR)(*it).m_pszItemData);
}
UpdateHorzExtent(m_ctlFileType, 16); // adjust dropped width to ensure all strings are fully visible
// restore previous selected entry by value (language independent)
if (!m_ctlFileType.SelectItemDataStringA(strCurSelFileType))
{
if (!m_ctlFileType.SelectString(GetResString(IDS_SEARCH_ANY)))
m_ctlFileType.SetCurSel(0);
}
}
void CSearchParamsWnd::Localize()
{
SetWindowText(GetResString(IDS_SEARCHPARAMS));
GetDlgItem(IDC_MSTATIC3)->SetWindowText(GetResString(IDS_SW_NAME));
GetDlgItem(IDC_MSTATIC7)->SetWindowText(GetResString(IDS_TYPE));
GetDlgItem(IDC_SEARCH_RESET)->SetWindowText(GetResString(IDS_PW_RESET));
GetDlgItem(IDC_METH)->SetWindowText(GetResString(IDS_METHOD));
GetDlgItem(IDC_SEARCH_UNICODE)->SetWindowText(GetResString(IDS_SEARCH_UNICODE));
m_ctlStart.SetWindowText(GetResString(IDS_SW_START));
m_ctlCancel.SetWindowText(GetResString(IDS_CANCEL));
m_ctlMore.SetWindowText(GetResString(IDS_MORE));
SetWindowText(GetResString(IDS_SEARCHPARAMS));
InitMethodsCtrl();
InitFileTypesCtrl();
m_ctlOpts.SetItemText(orMinSize, 0, GetResString(IDS_SEARCHMINSIZE));
m_ctlOpts.SetItemText(orMaxSize, 0, GetResString(IDS_SEARCHMAXSIZE));
m_ctlOpts.SetItemText(orAvailability, 0, GetResString(IDS_SEARCHAVAIL));
m_ctlOpts.SetItemText(orExtension, 0, GetResString(IDS_SEARCHEXTENTION));
m_ctlOpts.SetItemText(orCompleteSources, 0, GetResString(IDS_COMPLSOURCES));
m_ctlOpts.SetItemText(orCodec, 0, GetResString(IDS_CODEC));
m_ctlOpts.SetItemText(orBitrate, 0, GetResString(IDS_MINBITRATE));
m_ctlOpts.SetItemText(orLength, 0, GetResString(IDS_MINLENGTH));
m_ctlOpts.SetItemText(orTitle, 0, GetResString(IDS_TITLE));
m_ctlOpts.SetItemText(orAlbum, 0, GetResString(IDS_ALBUM));
m_ctlOpts.SetItemText(orArtist, 0, GetResString(IDS_ARTIST));
}
BOOL CSearchParamsWnd::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_ESCAPE)
return FALSE;
if ( m_pacSearchString && m_pacSearchString->IsBound()
&& (pMsg->wParam == VK_DELETE && pMsg->hwnd == m_ctlName.m_hWnd && (GetAsyncKeyState(VK_MENU)<0 || GetAsyncKeyState(VK_CONTROL)<0)))
m_pacSearchString->Clear();
if (pMsg->wParam == VK_RETURN && m_ctlStart.IsWindowEnabled())
{
if (m_pacSearchString && m_pacSearchString->IsBound() && pMsg->hwnd == m_ctlName.m_hWnd)
{
CString strText;
m_ctlName.GetWindowText(strText);
if (!strText.IsEmpty())
{
m_ctlName.SetWindowText(_T("")); // this seems to be the only chance to let the dropdown list to disapear
m_ctlName.SetWindowText(strText);
m_ctlName.SetSel(strText.GetLength(), strText.GetLength());
}
}
}
}
return CDialogBar::PreTranslateMessage(pMsg);
}
void CSearchParamsWnd::OnBnClickedStart()
{
m_ctlMore.EnableWindow(FALSE);
if (m_ctlOpts.GetEditCtrl()->GetSafeHwnd())
m_ctlOpts.CommitEditCtrl();
SSearchParams* pParams = GetParameters();
if (pParams)
{
if (!pParams->strExpression.IsEmpty())
{
if (m_pacSearchString && m_pacSearchString->IsBound())
m_pacSearchString->AddItem(pParams->strExpression, 0);
m_searchdlg->StartSearch(pParams);
}
else
delete pParams;
}
}
void CSearchParamsWnd::OnBnClickedMore()
{
CWnd* pWndFocus = GetFocus();
m_ctlMore.EnableWindow(FALSE);
if (pWndFocus && pWndFocus->m_hWnd == m_ctlMore.m_hWnd)
m_ctlStart.SetFocus();
if (m_searchdlg->SearchMore())
{
pWndFocus = GetFocus();
m_ctlStart.EnableWindow(FALSE);
if (pWndFocus && pWndFocus->m_hWnd == m_ctlStart.m_hWnd)
m_ctlName.SetFocus();
m_ctlCancel.EnableWindow(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -