CPI_Indicators.c
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:4k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. ////////////////////////////////////////////////////////////////////////////////
  2. #include "stdafx.h"
  3. #include "globals.h"
  4. #include "CPI_InterfacePart.h"
  5. ////////////////////////////////////////////////////////////////////////////////
  6. //
  7. typedef struct _CPs_IndicatorValue
  8. {
  9.     char* m_pcName;
  10.     char* m_pcValue;
  11.     void* m_pNext;
  12. } CPs_IndicatorValue;
  13. //
  14. //
  15. typedef struct _CPs_IndicatorBinding
  16. {
  17.     char* m_pcName;
  18.     CP_HINTERFACEPART m_hPart;
  19.     void* m_pNext;
  20. } CPs_IndicatorBinding;
  21. //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. CPs_IndicatorValue* glb_pIndicatorValue = NULL;
  24. CPs_IndicatorBinding* glb_pIndicatorBinding = NULL;
  25. ////////////////////////////////////////////////////////////////////////////////
  26. //
  27. //
  28. //
  29. void CPIC_FreeIndicators()
  30. {
  31.     CPs_IndicatorValue* pValueCursor;
  32.     CPs_IndicatorValue* pValueCursor_next;
  33.     for(pValueCursor = glb_pIndicatorValue; pValueCursor; pValueCursor = pValueCursor_next)
  34.     {
  35.         pValueCursor_next = (CPs_IndicatorValue*)pValueCursor->m_pNext;
  36.         free(pValueCursor->m_pcName);
  37.         free(pValueCursor->m_pcValue);
  38.         free(pValueCursor);
  39.     }
  40. }
  41. //
  42. //
  43. //
  44. CPs_IndicatorValue* CPIC_LookupIndicator_Value(const char* pcName)
  45. {
  46.     CPs_IndicatorValue* pValueCursor;
  47.     for(pValueCursor = glb_pIndicatorValue; pValueCursor; pValueCursor = (CPs_IndicatorValue*)pValueCursor->m_pNext)
  48.     {
  49.         if(stricmp(pValueCursor->m_pcName, pcName) == 0)
  50.             return pValueCursor;
  51.     }
  52.     return NULL;
  53. }
  54. //
  55. //
  56. //
  57. void CPIC_SetIndicatorValue(const char* pcName, const char* pcValue)
  58. {
  59.     CPs_IndicatorValue* pIndicatorValue;
  60.     pIndicatorValue = CPIC_LookupIndicator_Value(pcName);
  61.     // No value found - create one
  62.     if(!pIndicatorValue)
  63.     {
  64.         pIndicatorValue = (CPs_IndicatorValue*)malloc(sizeof(CPs_IndicatorValue));
  65.         STR_AllocSetString(&pIndicatorValue->m_pcName, pcName, FALSE);
  66.         pIndicatorValue->m_pcValue = NULL;
  67.         // Link in
  68.         pIndicatorValue->m_pNext = glb_pIndicatorValue;
  69.         glb_pIndicatorValue = pIndicatorValue;
  70.     }
  71.     // Set value
  72.     STR_AllocSetString(&pIndicatorValue->m_pcValue, pcValue, TRUE);
  73.     // Invalidate any bound controls
  74.     {
  75.         CPs_IndicatorBinding* pBindingCursor;
  76.         for(pBindingCursor = glb_pIndicatorBinding; pBindingCursor; pBindingCursor = (CPs_IndicatorBinding*)pBindingCursor->m_pNext)
  77.         {
  78.             if(stricmp(pBindingCursor->m_pcName, pcName) == 0)
  79.                 IP_Invalidate(pBindingCursor->m_hPart);
  80.         }
  81.     }
  82. }
  83. //
  84. //
  85. //
  86. const char* CPIC_GetIndicatorValue(const char* pcName)
  87. {
  88.     CPs_IndicatorValue* pIndicatorValue;
  89.     pIndicatorValue = CPIC_LookupIndicator_Value(pcName);
  90.     if(pIndicatorValue)
  91.         return pIndicatorValue->m_pcValue;
  92.     return NULL;
  93. }
  94. //
  95. //
  96. //
  97. void CPIC_BindIndicatorToControl(const char* pcName, CP_HINTERFACEPART hPart)
  98. {
  99.     CPs_IndicatorBinding* pIndicatorBinding;
  100.     pIndicatorBinding = (CPs_IndicatorBinding*)malloc(sizeof(CPs_IndicatorBinding));
  101.     STR_AllocSetString(&pIndicatorBinding->m_pcName, pcName, FALSE);
  102.     pIndicatorBinding->m_hPart = hPart;
  103.     // Link in
  104.     pIndicatorBinding->m_pNext = glb_pIndicatorBinding;
  105.     glb_pIndicatorBinding = pIndicatorBinding;
  106. }
  107. //
  108. //
  109. //
  110. void CPIC_UnBindControl(CP_HINTERFACEPART hPart)
  111. {
  112.     CPs_IndicatorBinding* pBindingCursor;
  113.     CPs_IndicatorBinding** ppBindingCursor_Referrer;
  114.     for(pBindingCursor = glb_pIndicatorBinding, ppBindingCursor_Referrer = &glb_pIndicatorBinding;
  115.             pBindingCursor;
  116.             pBindingCursor = (CPs_IndicatorBinding*)pBindingCursor->m_pNext,
  117.             ppBindingCursor_Referrer = (CPs_IndicatorBinding**)&pBindingCursor->m_pNext)
  118.     {
  119.         if(pBindingCursor->m_hPart == hPart)
  120.         {
  121.             *ppBindingCursor_Referrer = (CPs_IndicatorBinding*)pBindingCursor->m_pNext;
  122.             free(pBindingCursor->m_pcName);
  123.             free(pBindingCursor);
  124.             return;
  125.         }
  126.     }
  127. }
  128. //
  129. //
  130. //