/*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#include "../client/DCPlusPlus.h"
#include "Resource.h"
#include "FilterPage.h"
#include "FilterPageDlg.h"
#include "../client/SettingsManager.h"
#include "../client/FavoriteManager.h"
#include "WinUtil.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
PropPage::TextItem FilterPage::texts[] = {
{ IDC_ADD_FILTER, ResourceManager::ADD },
{ IDC_CHANGE_FILTER, ResourceManager::SETTINGS_CHANGE },
{ IDC_REMOVE_FILTER, ResourceManager::REMOVE },
{ 0, ResourceManager::SETTINGS_AUTO_AWAY }
};
PropPage::Item FilterPage::items[] = {
{ 0, 0, PropPage::T_END }
};
LRESULT FilterPage::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
PropPage::translate((HWND)(*this), texts);
PropPage::read((HWND)*this, items);
CRect rc;
ctrlFilters.Attach(GetDlgItem(IDC_FILTER_PAGE_ITEMS));
ctrlFilters.GetClientRect(rc);
ctrlFilters.InsertColumn(0, CTSTRING(SETTINGS_FSTRING), LVCFMT_LEFT, rc.Width() / 1, 0);
DWORD styles = LVS_EX_LABELTIP;
if (BOOLSETTING(FULL_ROW_SELECT))
styles |= LVS_EX_FULLROWSELECT;
if (BOOLSETTING(SHOW_INFOTIPS))
styles |= LVS_EX_INFOTIP;
if (BOOLSETTING(HIGHLIGHT_MOUSEOVER))
styles |= LVS_EX_UNDERLINEHOT | LVS_EX_ONECLICKACTIVATE;
if(!(WinUtil::getOsMajor() >= 5 && WinUtil::getOsMinor() >= 1 //WinXP & WinSvr2003
|| WinUtil::getOsMajor() >= 6 )) //Vista
{
styles |= 0x00010000;
}
ctrlFilters.SetExtendedListViewStyle(styles);
// Do specialized reading here.
Filters::List& ul = FavoriteManager::getInstance()->getFilters();
TStringList cols;
for(Filters::Iter j = ul.begin(); j != ul.end(); ++j) {
cols.push_back(Text::toT(j->getFstring()));
ctrlFilters.insert(cols);
cols.clear();
}
return TRUE;
}
LRESULT FilterPage::onAddFilter(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
FilterPageDlg dlg;
if(dlg.DoModal() == IDOK) {
TStringList lst;
lst.push_back(dlg.fstring);
ctrlFilters.insert(lst);
}
return 0;
}
LRESULT FilterPage::onChangeFilter(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
if(ctrlFilters.GetSelectedCount() == 1) {
int sel = ctrlFilters.GetNextItem(-1, LVNI_SELECTED);
TCHAR buf[256];
FilterPageDlg dlg;
ctrlFilters.GetItemText(sel, 0, buf, 256);
dlg.fstring = buf;
if(dlg.DoModal() == IDOK) {
ctrlFilters.SetItemText(sel, 0, dlg.fstring.c_str());
}
}
return 0;
}
LRESULT FilterPage::onRemoveFilter(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
if(ctrlFilters.GetSelectedCount() == 1) {
ctrlFilters.DeleteItem(ctrlFilters.GetNextItem(-1, LVNI_SELECTED));
}
return 0;
}
void FilterPage::write() {
int it = ctrlFilters.GetItemCount();
#define BUFLEN 256
TCHAR buf[BUFLEN];
tstring fstring, type;
Filters::List& ul = FavoriteManager::getInstance()->getFilters();
ul.clear();
for(int i = 0; i < it; ++i) {
ctrlFilters.GetItemText(i, 0, buf, BUFLEN);
fstring = buf;
ul.push_back(Filters(Text::fromT(fstring)));
}
FavoriteManager::getInstance()->saveFilters();
PropPage::write((HWND)*this, items);
}
/**
* @file
* $Id: FilterPage.cpp 109 2006-10-31 03:21:46Z crakter $
*/