📄 baselist.cpp
字号:
// BaseList.cpp: implementation of the BaseList class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SM.h"
#include "BaseList.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=40A481F70253
BaseList::BaseList(CListCtrl * plist)
{
ASSERT(plist);
pList = plist;
pList->SetExtendedStyle(pList->GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES );
}
//##ModelId=40A481F70261
BaseList::~BaseList()
{
}
//##ModelId=40A481F70251
void BaseList::Init()
{
}
//##ModelId=40A481F70245
bool BaseList::IsSelected()
{
POSITION pos;
pos = pList->GetFirstSelectedItemPosition();
return pos!=NULL;
}
//##ModelId=40A481F70242
DWORD BaseList::GetSelectedData(long i)
{
long i_sel = GetSelected(i);
if(i_sel != -1)
return pList->GetItemData(i_sel);
else
return -1L;
}
//##ModelId=40A481F70235
inline long BaseList::GetSelectedCount()
{
return pList->GetSelectedCount();
}
//##ModelId=40A481F70232
long BaseList::GetSelected(long i)
{
POSITION pos;
pos = pList->GetFirstSelectedItemPosition();
long index = 0, i_sel;
while(pos)
{
i_sel = pList->GetNextSelectedItem(pos);
if(index==i)
return i_sel;
index++;
}
return -1;
}
//##ModelId=40A481F70216
inline void BaseList::SetSelected(long i)
{
pList->SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
}
//##ModelId=40A481F70215
void BaseList::Clear()
{
pList->DeleteAllItems();
}
//##ModelId=40A481F70205
long BaseList::Find(int sub_item, CString &s)
{
int row_count = pList->GetItemCount();
int col_count = GetColCount();
if(sub_item>=col_count)
return -1L;
for(int i=0; i<row_count; i++)
if(pList->GetItemText(i, sub_item)==s)
return i;
return -1L;
}
//##ModelId=40A481F70204
inline long BaseList::GetColCount()
{
return pList->GetHeaderCtrl()->GetItemCount();
}
//##ModelId=40A481F701F5
inline void BaseList::Delete(long i)
{
pList->DeleteItem(i);
}
//##ModelId=40A481F701F4
inline CListCtrl* BaseList::GetListCtrl()
{
return pList;
}
//##ModelId=40A481F701E9
CHeaderCtrl* BaseList::GetHeaderCtrl()
{
return pList->GetHeaderCtrl();
}
//##ModelId=40A481F701C7
void BaseList::SelectAll()
{
if(IsCanSelectAll())
{
int count = pList->GetItemCount();
for(int i=0; i<count; i++)
pList->SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
}
}
//##ModelId=40A481F701C6
void BaseList::UnSelectAll()
{
if(IsCanSelectAll())
{
int count = pList->GetItemCount();
for(int i=0; i<count; i++)
pList->SetItemState(i, 0, LVIS_SELECTED );
}
}
//##ModelId=40A481F701C5
bool BaseList::IsCanSelectAll()
{
return (pList->GetStyle()&LVS_SINGLESEL)==0L;
}
//##ModelId=40A481F701B5
long BaseList::GetCount()
{
return pList->GetItemCount();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -