GraphLegend.cpp
上传用户:tianjwyx
上传日期:2007-01-13
资源大小:813k
文件大小:2k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. //GraphLegend.cpp - Version 3.0 (Brian Convery, May, 2001)
  2. #include "stdafx.h"
  3. #include "GraphLegend.h"
  4. #include "GraphLegendSet.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CGraphLegend
  12. CGraphLegend::CGraphLegend()
  13. {
  14. legendLabels = new CObList();
  15. legendLength = 0;
  16. }
  17. CGraphLegend::~CGraphLegend()
  18. {
  19. POSITION pos;
  20. CGraphLegendSet *legendSet;
  21. pos = legendLabels->GetHeadPosition();
  22. while(pos != NULL)
  23. {
  24. legendSet = (CGraphLegendSet*)legendLabels->GetAt(pos);
  25. legendLabels->RemoveAt(pos);
  26. delete legendSet;
  27. }
  28. delete legendLabels;
  29. }
  30. BEGIN_MESSAGE_MAP(CGraphLegend, CStatic)
  31. //{{AFX_MSG_MAP(CGraphLegend)
  32. // NOTE - the ClassWizard will add and remove mapping macros here.
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CGraphLegend message handlers
  37. void CGraphLegend::SetLegendText(int datagroup, CString label)
  38. {
  39. CGraphLegendSet *legendData = new CGraphLegendSet();
  40. legendData->SetLegendLabel(datagroup, label);
  41. legendLabels->AddTail(legendData);
  42. if(label.GetLength() > legendLength)
  43. legendLength = label.GetLength();
  44. }
  45. CString CGraphLegend::GetLegendText(int datagroup)
  46. {
  47. POSITION pos;
  48. CGraphLegendSet *legendData;
  49. if((legendLabels->GetCount() < datagroup) || (legendLabels->GetCount() == 0))
  50. return "";
  51. pos = legendLabels->GetHeadPosition();
  52. for(int i = 0; i < datagroup; i++)
  53. legendLabels->GetNext(pos);
  54. legendData = (CGraphLegendSet*)legendLabels->GetAt(pos);
  55. return legendData->GetLegendLabel();
  56. }
  57. int CGraphLegend::GetLegendLength()
  58. {
  59. return legendLength;
  60. }
  61. void CGraphLegend::Remove(int dataGroup)
  62. {
  63. POSITION pos;
  64. CGraphLegendSet *legendSet;
  65. pos = legendLabels->GetHeadPosition();
  66. for(int i = 0; i < dataGroup; i++)
  67. {
  68. legendSet = (CGraphLegendSet*)legendLabels->GetAt(pos);
  69. legendLabels->GetNext(pos);
  70. }
  71. legendLabels->RemoveAt(pos);
  72. delete legendSet;
  73. }
  74. void CGraphLegend::RemoveAll()
  75. {
  76. POSITION pos;
  77. CGraphLegendSet *legendSet;
  78. pos = legendLabels->GetHeadPosition();
  79. while(pos != NULL)
  80. {
  81. legendSet = (CGraphLegendSet*)legendLabels->GetAt(pos);
  82. legendLabels->RemoveAt(pos);
  83. delete legendSet;
  84. }
  85. }