funclist.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "stdafx.h"
  2. #include "funclist.h"
  3. IMPLEMENT_DYNAMIC( FuncList,CListCtrl )
  4. BEGIN_MESSAGE_MAP( FuncList,CListCtrl )
  5. ON_WM_CREATE()
  6. ON_NOTIFY_REFLECT( NM_CLICK,nm_click )
  7. END_MESSAGE_MAP()
  8. FuncList::FuncList():
  9. listener(0){
  10. }
  11. void FuncList::setListener( FuncListListener *l ){
  12. listener=l;
  13. }
  14. int FuncList::OnCreate( LPCREATESTRUCT cs ){
  15. CListCtrl::OnCreate( cs );
  16. return 0;
  17. }
  18. void FuncList::nm_click( NMHDR *nmhdr,LRESULT *result ){
  19. NMLISTVIEW *lv=(NMLISTVIEW*)nmhdr;
  20. int k=0;
  21. Funcs::iterator it;
  22. for( it=funcs.begin();it!=funcs.end() && k<lv->iItem;++k,++it ){
  23. }
  24. if( it!=funcs.end() ){
  25. listener->funcSelected( *it );
  26. }
  27. *result=0;
  28. }
  29. void FuncList::clear(){
  30. funcs.clear();
  31. DeleteAllItems();
  32. }
  33. void FuncList::insert( int line,const string &func ){
  34. int n=0;
  35. Funcs::iterator it;
  36. for( it=funcs.begin();it!=funcs.end() && line>*it;++n,++it ){
  37. }
  38. if( it!=funcs.end() && line==*it ){
  39. SetItemText( n,0,func.c_str() );
  40. return;
  41. }
  42. it=funcs.insert( it,line );
  43. InsertItem( n,func.c_str() );
  44. }
  45. void FuncList::remove( int begin,int end ){
  46. int n=0;
  47. Funcs::iterator it;
  48. for( it=funcs.begin();it!=funcs.end() && *it<begin;++n,++it ){
  49. }
  50. while( it!=funcs.end() && *it<end ){
  51. funcs.erase( it++ );
  52. DeleteItem( n );
  53. }
  54. }
  55. void FuncList::relocate( int begin,int offset ){
  56. Funcs::iterator it;
  57. for( it=funcs.begin();it!=funcs.end();++it ){
  58. if( *it>=begin ) *it+=offset;
  59. }
  60. }