1 Star 0 Fork 0

soui3-demo/mclistview_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
StudentSmsDlg.cpp 18.45 KB
一键复制 编辑 原始数据 按行查看 历史
setoutsoft 提交于 2019-11-27 14:46 . 移植到了3.0,增加DPI支持。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
#include "stdafx.h"
#include "StudentSmsDlg.h"
#include <helper/SAdapterBase.h>
#include <helper/STime.h>
class SStudentSearchAdapter : public SAdapterBase
{
friend class CStudentAdapter;
public:
struct StudentInfo2
{
SStringT strText;
int bExpired;
int nPos;
};
StudentInfo2 GetItem(int i){return m_searchResult[i];}
protected:
virtual int getCount()
{
return m_searchResult.GetCount();
}
virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
{
if(pItem->GetChildrenCount() == 0)
{
pItem->InitFromXml(xmlTemplate);
}
pItem->FindChildByID(R.id.txt_key)->SetWindowText(m_searchResult[position].strText);
}
protected:
SArray<StudentInfo2> m_searchResult;
};
class CStudentAdapter : public SMcAdapterBase
{
protected:
enum{
VT_GROUP,
VT_DATA,
};
struct StudentInfo{
SStringT strNick;
UINT imid;//yy 号
SOUI::STime tm1;
SOUI::STime tm2;
int nLoyalDegree;
BOOL bChecked;
};
SArray<StudentInfo> m_stuCurrent,m_stuExpired;
BOOL m_bCurrentExpand, m_bExpiredExpand;
BOOL m_bAllCurrentChecked, m_bAllExpiredChecked;
IStudentCheckChanged * m_pSelChangedHandler;
public:
CStudentAdapter(IStudentCheckChanged * pSelChangedHandler)
:m_pSelChangedHandler(pSelChangedHandler)
,m_bCurrentExpand(TRUE),m_bExpiredExpand(FALSE)
,m_bAllCurrentChecked(FALSE),m_bAllExpiredChecked(FALSE)
{
StudentInfo data[] =
{
{
_T("sb no.1"),100,
SOUI::STime(2015,9,1,0,0,0),
SOUI::STime(2016,9,1,0,0,0),
10000,0
},
{
_T("sb no.2"),200,
SOUI::STime(2015,9,2,0,0,0),
SOUI::STime(2016,9,2,0,0,0),
100000,0
},
{
_T("sb no.3"),300,
SOUI::STime(2015,9,3,0,0,0),
SOUI::STime(2016,9,3,0,0,0),
100000,0
},
};
for(int i=0;i<ARRAYSIZE(data);i++)
{
m_stuCurrent.Add(data[i]);
}
StudentInfo data2[] =
{
{
_T("nb no.1"),400,
SOUI::STime(2015,9,1,0,0,0),
SOUI::STime(2016,9,1,0,0,0),
0,0
},
{
_T("nb no.2"),500,
SOUI::STime(2015,9,2,0,0,0),
SOUI::STime(2016,9,2,0,0,0),
0,0
},
{
_T("nb no.3"),600,
SOUI::STime(2015,9,3,0,0,0),
SOUI::STime(2016,9,3,0,0,0),
0,0
},
};
for(int i=0;i<ARRAYSIZE(data2);i++)
{
m_stuExpired.Add(data2[i]);
}
}
int Search(const SStringT & strKey,SStudentSearchAdapter *pSearchAdapter)
{
if(strKey.IsEmpty()) return 0;
for(UINT i=0;i<m_stuCurrent.GetCount();i++)
{
SStringT str = SStringT().Format(_T("%s(%u)"),m_stuCurrent[i].strNick,m_stuCurrent[i].imid);
if(str.Find(strKey)!=-1)
{
SStudentSearchAdapter::StudentInfo2 info;
info.strText = str;
info.bExpired = FALSE;
info.nPos = i;
pSearchAdapter->m_searchResult.Add(info);
}
}
for(UINT i=0;i<m_stuExpired.GetCount();i++)
{
SStringT str = SStringT().Format(_T("%s(%u)"),m_stuExpired[i].strNick,m_stuExpired[i].imid);
if(str.Find(strKey)!=-1)
{
SStudentSearchAdapter::StudentInfo2 info;
info.strText = str;
info.bExpired = TRUE;
info.nPos = i;
pSearchAdapter->m_searchResult.Add(info);
}
}
return pSearchAdapter->m_searchResult.GetCount();
}
int EnsureKeyVisible(BOOL bExpired,int iItem)
{
if(!bExpired)
{
if(!m_bCurrentExpand)
{
m_bCurrentExpand = TRUE;
notifyDataSetChanged();
}
return 1+iItem;
}else
{
if(!m_bExpiredExpand)
{
m_bExpiredExpand = TRUE;
notifyDataSetChanged();
}
return 2 + iItem + (m_bCurrentExpand?m_stuCurrent.GetCount():0);
}
}
protected:
virtual int getCount()
{
return 2 + (m_bCurrentExpand?m_stuCurrent.GetCount():0) + (m_bExpiredExpand?m_stuExpired.GetCount():0);
}
virtual int getItemViewType(int position)
{
if(position == 0 || position == 1+ (m_bCurrentExpand?m_stuCurrent.GetCount():0))
return VT_GROUP;
else
return VT_DATA;
}
virtual int getViewTypeCount()
{
return 2;
}
virtual SStringW GetColumnName(int iCol) const
{
SStringW colNames[] = {L"col_nick",L"col_time_span",L"col_loyal_degree"};
return colNames[iCol];
}
virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
{
int nViewType = getItemViewType(position);
if(pItem->GetChildrenCount() == 0)
{
pugi::xml_node xmlItem;
switch(nViewType)
{
case VT_GROUP: xmlItem = xmlTemplate.child(L"item_group");break;
case VT_DATA: xmlItem = xmlTemplate.child(L"item_data");break;
}
pItem->InitFromXml(xmlItem);
}
if(nViewType == VT_GROUP)
{
SToggle * pSwitch=pItem->FindChildByID2<SToggle>(R.id.tgl_tv_expand);
pSwitch->SetToggle(position==0?m_bCurrentExpand:m_bExpiredExpand);
pSwitch->GetEventSet()->subscribeEvent(EVT_CMD,Subscriber(&CStudentAdapter::OnBtnGroupExpand,this));
pItem->FindChildByID(R.id.txt_group)->SetWindowText(S_CW2T(TR(GETSTRING(position==0?R.string.current_student:R.string.expired_student),L"")));
pItem->GetEventSet()->subscribeEvent(EVT_ITEMPANEL_DBCLICK,Subscriber(&CStudentAdapter::OnGroupDblClick,this));
SCheckBox *pGroupCheck = pItem->FindChildByID2<SCheckBox>(R.id.chk_select_group);
pGroupCheck->GetEventSet()->subscribeEvent(EVT_STATECHANGED,Subscriber(&CStudentAdapter::OnGroupSelectCheckChanged,this));
pGroupCheck->GetEventSet()->setMutedState(true);
pGroupCheck->SetCheck(position==0?m_bAllCurrentChecked:m_bAllExpiredChecked);
pGroupCheck->GetEventSet()->setMutedState(false);
}else
{
int nBaseCurrent = 1;
int nBaseExpired = 1 + (m_bCurrentExpand?m_stuCurrent.GetCount():0) + 1;
if(position< nBaseExpired)
{//current student
StudentInfo & stuInfo = m_stuCurrent[position-nBaseCurrent];
SCheckBox *pCheckBox = pItem->FindChildByID2<SCheckBox>(R.id.txt_nick);
pCheckBox->GetEventSet()->subscribeEvent(EVT_STATECHANGED,Subscriber(&CStudentAdapter::OnStudentCheckChanged,this));
pCheckBox->GetEventSet()->setMutedState(true);
pCheckBox->SetCheck(stuInfo.bChecked);
pCheckBox->GetEventSet()->setMutedState(false);
pCheckBox->SetWindowText(SStringT().Format(_T("%s(%u)"),stuInfo.strNick,stuInfo.imid));
pItem->FindChildByID(R.id.txt_loyal_degree)->SetWindowText(SStringT().Format(_T("%d"),stuInfo.nLoyalDegree));
pItem->FindChildByID(R.id.txt_time_span)->SetWindowText(stuInfo.tm1.Format(_T("%Y/%m/%d") + SStringT(_T(" - ")) + stuInfo.tm2.Format(_T("%Y/%m/%d"))));
}else
{//expired student
StudentInfo & stuInfo = m_stuExpired[position-nBaseExpired];
SCheckBox *pCheckBox = pItem->FindChildByID2<SCheckBox>(R.id.txt_nick);
pCheckBox->GetEventSet()->subscribeEvent(EVT_STATECHANGED,Subscriber(&CStudentAdapter::OnStudentCheckChanged,this));
pCheckBox->GetEventSet()->setMutedState(true);
pCheckBox->SetCheck(stuInfo.bChecked);
pCheckBox->GetEventSet()->setMutedState(false);
pCheckBox->SetWindowText(SStringT().Format(_T("%s(%u)"),stuInfo.strNick,stuInfo.imid));
pItem->FindChildByID(R.id.txt_loyal_degree)->SetWindowText(SStringT().Format(_T("%d"),stuInfo.nLoyalDegree));
pItem->FindChildByID(R.id.txt_time_span)->SetWindowText(stuInfo.tm1.Format(_T("%Y/%m/%d") + SStringT(_T(" - ")) + stuInfo.tm2.Format(_T("%Y/%m/%d"))));
}
}
}
bool OnBtnGroupExpand(EventArgs *e)
{
SToggle *pTgl = sobj_cast<SToggle>(e->sender);
SASSERT(pTgl);
SItemPanel * pItem = sobj_cast<SItemPanel>(pTgl->GetRoot());
SASSERT(pItem);
int position = (int)pItem->GetItemIndex();
if(position == 0)
m_bCurrentExpand = pTgl->GetToggle();
else
m_bExpiredExpand = pTgl->GetToggle();
notifyDataSetChanged();
return true;
}
bool OnGroupDblClick(EventArgs *e)
{
SItemPanel *pItem = sobj_cast<SItemPanel>(e->sender);
SASSERT(pItem);
int position = (int)pItem->GetItemIndex();
if(position == 0) m_bCurrentExpand = !m_bCurrentExpand;
else m_bExpiredExpand = !m_bExpiredExpand;
notifyDataSetChanged();
return true;
}
bool OnGroupSelectCheckChanged(EventArgs *e)
{
EventSwndStateChanged *e2 = sobj_cast<EventSwndStateChanged>(e);
SASSERT(e2);
if(!e2->CheckState(WndState_Check))
return false;
SCheckBox *pCheckBox = sobj_cast<SCheckBox>(e->sender);
SASSERT(pCheckBox);
SItemPanel * pItem = sobj_cast<SItemPanel>(pCheckBox->GetRoot());
int position = (int)pItem->GetItemIndex();
int nSelCur = 0, nSelExp=0;
if(position == 0)
{
for(UINT i=0;i<m_stuCurrent.GetCount();i++)
{
m_stuCurrent[i].bChecked = (e2->dwNewState & WndState_Check)!=0;
nSelCur += m_stuCurrent[i].bChecked;
}
for(UINT i=0;i<m_stuExpired.GetCount();i++)
{
nSelExp += m_stuExpired[i].bChecked;
}
}else
{
for(UINT i=0;i<m_stuCurrent.GetCount();i++)
{
nSelCur += m_stuCurrent[i].bChecked;
}
for(UINT i=0;i<m_stuExpired.GetCount();i++)
{
m_stuExpired[i].bChecked = (e2->dwNewState & WndState_Check)!=0;;
nSelExp += m_stuExpired[i].bChecked;
}
}
m_bAllCurrentChecked = nSelCur == m_stuCurrent.GetCount();
m_bAllExpiredChecked = nSelExp == m_stuExpired.GetCount();
notifyDataSetChanged();
if(m_pSelChangedHandler)
m_pSelChangedHandler->OnStudentCheckChanged(nSelCur,nSelExp);
return true;
}
bool OnStudentCheckChanged(EventArgs *e)
{
EventSwndStateChanged *e2 = sobj_cast<EventSwndStateChanged>(e);
if(!e2->CheckState(WndState_Check))
return false;
SCheckBox *pCheck = sobj_cast<SCheckBox>(e->sender);
SASSERT(pCheck);
SItemPanel * pItem = sobj_cast<SItemPanel>(pCheck->GetRoot());
int position = (int)pItem->GetItemIndex();
int nBaseCurrent = 1;
int nBaseExpired = 1 + (m_bCurrentExpand?m_stuCurrent.GetCount():0) + 1;
if(position < nBaseExpired)
{
m_stuCurrent[position - nBaseCurrent].bChecked = pCheck->IsChecked();
}else
{
m_stuExpired[position - nBaseExpired].bChecked = pCheck->IsChecked();
}
if(m_pSelChangedHandler)
{
int nSelCur = 0, nSelExp=0;
for(UINT i=0;i<m_stuCurrent.GetCount();i++)
{
nSelCur += m_stuCurrent[i].bChecked;
}
for(UINT i=0;i<m_stuExpired.GetCount();i++)
{
nSelExp += m_stuExpired[i].bChecked;
}
BOOL bAllCurrentChecked = nSelCur == m_stuCurrent.GetCount();
BOOL bAllExpiredChecked = nSelExp == m_stuExpired.GetCount();
if(bAllCurrentChecked!=m_bAllCurrentChecked || bAllExpiredChecked != m_bAllExpiredChecked)
{
m_bAllCurrentChecked = bAllCurrentChecked;
m_bAllExpiredChecked = bAllExpiredChecked;
notifyDataSetChanged();
}
m_pSelChangedHandler->OnStudentCheckChanged(nSelCur,nSelExp);
}
return true;
}
};
class CSmsRecordAdapter : public SAdapterBase
{
protected:
struct RecordInfo
{
SOUI::STime tmSend;
SStringT strReceiver;
SStringT strContent;
};
SArray<RecordInfo> m_smsRecord;
public:
CSmsRecordAdapter()
{
RecordInfo recs[] =
{
{
SOUI::STime(2015,9,1,0,0,0),
_T("sb no.1"),
_T("A股明天暴跌,有钱没钱使劲买。"),
},
{
SOUI::STime(2015,9,1,0,0,0),
_T("sb no.2"),
_T("A股明天暴跌,有钱没钱使劲买。"),
},
{
SOUI::STime(2015,9,1,0,0,0),
_T("sb no.3"),
_T("A股明天暴跌,有钱没钱使劲买。"),
},
{
SOUI::STime(2015,9,1,0,0,0),
_T("sb no.4"),
_T("A股明天暴跌,有钱没钱使劲买。"),
},
{
SOUI::STime(2015,9,1,0,0,0),
_T("sb no.5"),
_T("A股明天暴跌,有钱没钱使劲买。"),
},
};
for(int i=0;i<ARRAYSIZE(recs);i++)
{
m_smsRecord.Add(recs[i]);
}
}
protected:
virtual int getCount()
{
return m_smsRecord.GetCount();
}
virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
{
if(pItem->GetChildrenCount() == 0)
{
pItem->InitFromXml(xmlTemplate);
}
RecordInfo & rec = m_smsRecord[position];
pItem->FindChildByID(R.id.txt_send_time)->SetWindowText(rec.tmSend.Format(_T("%Y/%m/%d %H:%M:%S")));
pItem->FindChildByID(R.id.txt_sms_receiver)->SetWindowText(rec.strReceiver);
pItem->FindChildByID(R.id.txt_sms_content)->SetWindowText(rec.strContent);
}
};
CStudentSmsDlg::CStudentSmsDlg(void)
: SOUI::SHostDialog(UIRES.layout.dlg_student_sms)
{
}
CStudentSmsDlg::~CStudentSmsDlg(void)
{
}
BOOL CStudentSmsDlg::OnInitDialog(HWND wndFocus, LPARAM lInitParam)
{
m_wndSmsRecord = FindChildByID(R.id.wnd_record_frame);
m_tvStudent = FindChildByID2<SMCListView>(R.id.tv_student);
IMcAdapter *pTvAdapter = new CStudentAdapter(this);
m_tvStudent->SetAdapter(pTvAdapter);
pTvAdapter->Release();
m_lvSmsRecord = FindChildByID2<SListView>(R.id.lv_sms_record);
ILvAdapter *pLvAdapter = new CSmsRecordAdapter;
m_lvSmsRecord->SetAdapter(pLvAdapter);
pLvAdapter->Release();
return TRUE;
}
void CStudentSmsDlg::OnBtnSmsRecord()
{
m_wndSmsRecord->SetVisible(TRUE,TRUE);
}
void CStudentSmsDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if(m_wndSmsRecord->IsVisible(TRUE) && !m_wndSmsRecord->GetWindowRect().PtInRect(point))
{
m_wndSmsRecord->SetVisible(FALSE,TRUE);
}
SetMsgHandled(FALSE);
}
void CStudentSmsDlg::OnStudentCheckChanged(int nSelCurrent, int nSelExpired)
{
FindChildByID(R.id.txt_sms_checked_num)->SetWindowText(SStringT().Format(_T("%d"),nSelCurrent + nSelExpired));
}
void CStudentSmsDlg::OnSearchFillList(EventArgs *e)
{
EventFillSearchDropdownList * e2 = sobj_cast<EventFillSearchDropdownList>(e);
SASSERT(e2);
CStudentAdapter * pStudentAdapter = (CStudentAdapter*)m_tvStudent->GetAdapter();
SStudentSearchAdapter * pSearchAdapter = new SStudentSearchAdapter;
if(pStudentAdapter->Search(e2->strKey,pSearchAdapter)>0)
{
SListView *pLvSearch = e2->pDropdownWnd->FindChildByID2<SListView>(R.id.lv_dropdown);
pLvSearch->SetAdapter(pSearchAdapter);
pLvSearch->SetSel(0);
e2->bPopup = true;
}
pSearchAdapter->Release();
}
void CStudentSmsDlg::OnSearchValue(EventArgs *e)
{
EventDropdownListSelected * e2 = sobj_cast<EventDropdownListSelected>(e);
SListView *pListView = e2->pDropdownWnd->FindChildByID2<SListView>(R.id.lv_dropdown);
SStudentSearchAdapter *pAdapter = (SStudentSearchAdapter*)pListView->GetAdapter();
if(e2->nValue == -1) return;
SStudentSearchAdapter::StudentInfo2 searchResult = pAdapter->GetItem(e2->nValue);
CStudentAdapter * pStudentAdapter = (CStudentAdapter*)m_tvStudent->GetAdapter();
int iItem = pStudentAdapter->EnsureKeyVisible(searchResult.bExpired,searchResult.nPos);
if(iItem != -1)
{
m_tvStudent->SetSel(iItem);
m_tvStudent->EnsureVisible(iItem);
}
}
void CStudentSmsDlg::OnSmsInputNotify(EventArgs *e)
{
EventRENotify *e2 = sobj_cast<EventRENotify>(e);
if(e2->iNotify != EN_CHANGE) return;
SEdit *pEdit = sobj_cast<SEdit>(e->sender);
int nLen = pEdit->GetWindowTextLength();
SWindow *pWordCount = FindChildByID(R.id.txt_wordcount);
pWordCount->SetWindowText(SStringT().Format(_T("%d"),nLen));
pWordCount->EnableWindow(nLen<100,TRUE);
}
void CStudentSmsDlg::OnScale(int nID)
{
int nScale = 100;
switch(nID)
{
case R.id.scale_100: nScale = 100;break;
case R.id.scale_150: nScale = 150;break;
case R.id.scale_200: nScale = 200;break;
}
int nCurScale = GetScale();
CRect rcWnd = GetWindowRect();
int OriWid = rcWnd.Width() * 100 / nCurScale;
int OriHei = rcWnd.Height() * 100/ nCurScale;
int nNewWid = OriWid * nScale / 100;
int nNewHei = OriHei * nScale / 100;
SDispatchMessage(UM_SETSCALE,nScale,0);
if(!IsZoomed()){
SetWindowPos(0, 0, 0, nNewWid, nNewHei, SWP_NOZORDER | SWP_NOMOVE);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/soui3-demo/mclistview_demo.git
git@gitee.com:soui3-demo/mclistview_demo.git
soui3-demo
mclistview_demo
mclistview_demo
master

搜索帮助