CPI_InterfacePart_CommandButton.c
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:5k
源码类别:

VC书籍

开发平台:

Visual C++

  1. ////////////////////////////////////////////////////////////////////////////////
  2. #include "stdafx.h"
  3. #include "globals.h"
  4. #include "CPI_InterfacePart.h"
  5. ////////////////////////////////////////////////////////////////////////////////
  6. //
  7. typedef struct _CPs_IPCommandButton
  8. {
  9.     CPs_Image_WithState* m_pStateImage;
  10.     CPe_ImageState m_enCurrentState;
  11.     wp_Verb m_pfnVerb;
  12.     BOOL m_bDown;
  13. } CPs_IPCommandButton;
  14. //
  15. ////////////////////////////////////////////////////////////////////////////////
  16. void IPCB_Destroy_PrivateData(CP_HINTERFACEPART hPart);
  17. void IPCB_Draw(CP_HINTERFACEPART hPart, CPs_DrawContext* pContext);
  18. void IPCB_onMouseIn(CP_HINTERFACEPART hPart);
  19. void IPCB_onMouseOut(CP_HINTERFACEPART hPart);
  20. void IPCB_onMouseButton_LDown(CP_HINTERFACEPART hPart, const POINTS ptMouse);
  21. void IPCB_onMouseButton_LUp(CP_HINTERFACEPART hPart, const POINTS ptMouse);
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //
  24. //
  25. //
  26. CP_HINTERFACEPART IP_Create_CommandButton(wp_Verb pfnVerb, CPs_Image_WithState* pImageWS)
  27. {
  28.     CPs_InterfacePart* pNewPart;
  29.     CPs_IPCommandButton* pCustomData;
  30.     // Setup custom data
  31.     pCustomData = (CPs_IPCommandButton*)malloc(sizeof(*pCustomData));
  32.     pCustomData->m_pStateImage = pImageWS;
  33.     pCustomData->m_enCurrentState = igsQuiescent;
  34.     pCustomData->m_pfnVerb = pfnVerb;
  35.     pCustomData->m_bDown = FALSE;
  36.     // Create new part and setup callbacks
  37.     pNewPart = (CPs_InterfacePart*)malloc(sizeof(*pNewPart));
  38.     memset(pNewPart, 0, sizeof(*pNewPart));
  39.     pNewPart->Destroy_PrivateData = IPCB_Destroy_PrivateData;
  40.     pNewPart->Draw = IPCB_Draw;
  41.     pNewPart->onMouseIn = IPCB_onMouseIn;
  42.     pNewPart->onMouseOut = IPCB_onMouseOut;
  43.     pNewPart->onMouseButton_LDown = IPCB_onMouseButton_LDown;
  44.     pNewPart->onMouseButton_LUp = IPCB_onMouseButton_LUp;
  45.     pNewPart->m_pPrivateData = pCustomData;
  46.     return pNewPart;
  47. }
  48. //
  49. //
  50. //
  51. void IPCB_Draw(CP_HINTERFACEPART hPart, CPs_DrawContext* pContext)
  52. {
  53.     CPs_InterfacePart* pIP;
  54.     CPs_IPCommandButton* pIPCB;
  55.     // Init
  56.     pIP = (CPs_InterfacePart*)hPart;
  57.     CP_CHECKOBJECT(pIP);
  58.     pIPCB = (CPs_IPCommandButton*)pIP->m_pPrivateData;
  59.     CP_CHECKOBJECT(pIPCB);
  60.     // Perform drawing
  61.     CPIG_DrawStateImage(pContext,
  62.                         pIP->m_rLocation.left, pIP->m_rLocation.top,
  63.                         pIPCB->m_pStateImage, pIPCB->m_enCurrentState);
  64. }
  65. //
  66. //
  67. //
  68. void IPCB_Destroy_PrivateData(CP_HINTERFACEPART hPart)
  69. {
  70.     CPs_InterfacePart* pIP;
  71.     CPs_IPCommandButton* pIPCB;
  72.     // Init
  73.     pIP = (CPs_InterfacePart*)hPart;
  74.     CP_CHECKOBJECT(pIP);
  75.     pIPCB = (CPs_IPCommandButton*)pIP->m_pPrivateData;
  76.     CP_CHECKOBJECT(pIPCB);
  77.     free(pIPCB);
  78. }
  79. //
  80. //
  81. //
  82. void IPCB_onMouseIn(CP_HINTERFACEPART hPart)
  83. {
  84.     CPs_InterfacePart* pIP;
  85.     CPs_IPCommandButton* pIPCB;
  86.     // Init
  87.     pIP = (CPs_InterfacePart*)hPart;
  88.     CP_CHECKOBJECT(pIP);
  89.     pIPCB = (CPs_IPCommandButton*)pIP->m_pPrivateData;
  90.     CP_CHECKOBJECT(pIPCB);
  91.     // Handler
  92.     if(pIPCB->m_bDown)
  93.         pIPCB->m_enCurrentState = igsActive;
  94.     else
  95.         pIPCB->m_enCurrentState = igsFloatActive;
  96.     IP_Invalidate(hPart);
  97. }
  98. //
  99. //
  100. //
  101. void IPCB_onMouseOut(CP_HINTERFACEPART hPart)
  102. {
  103.     CPs_InterfacePart* pIP;
  104.     CPs_IPCommandButton* pIPCB;
  105.     // Init
  106.     pIP = (CPs_InterfacePart*)hPart;
  107.     CP_CHECKOBJECT(pIP);
  108.     pIPCB = (CPs_IPCommandButton*)pIP->m_pPrivateData;
  109.     CP_CHECKOBJECT(pIPCB);
  110.     // Handler
  111.     pIPCB->m_enCurrentState = igsQuiescent;
  112.     IP_Invalidate(hPart);
  113. }
  114. //
  115. //
  116. //
  117. void IPCB_onMouseButton_LDown(CP_HINTERFACEPART hPart, const POINTS ptMouse)
  118. {
  119.     CPs_InterfacePart* pIP;
  120.     CPs_IPCommandButton* pIPCB;
  121.     // Init
  122.     pIP = (CPs_InterfacePart*)hPart;
  123.     CP_CHECKOBJECT(pIP);
  124.     pIPCB = (CPs_IPCommandButton*)pIP->m_pPrivateData;
  125.     CP_CHECKOBJECT(pIPCB);
  126.     // Handler
  127.     pIPCB->m_bDown = TRUE;
  128.     if(pIPCB->m_enCurrentState == igsFloatActive)
  129.         pIPCB->m_enCurrentState = igsActive;
  130.     IP_Invalidate(hPart);
  131. }
  132. //
  133. //
  134. //
  135. void IPCB_onMouseButton_LUp(CP_HINTERFACEPART hPart, const POINTS ptMouse)
  136. {
  137.     CPs_InterfacePart* pIP;
  138.     CPs_IPCommandButton* pIPCB;
  139.     // Init
  140.     pIP = (CPs_InterfacePart*)hPart;
  141.     CP_CHECKOBJECT(pIP);
  142.     pIPCB = (CPs_IPCommandButton*)pIP->m_pPrivateData;
  143.     CP_CHECKOBJECT(pIPCB);
  144.     // Handler
  145.     pIPCB->m_bDown = FALSE;
  146.     if(pIPCB->m_enCurrentState == igsActive)
  147.     {
  148.         // Mouse is still inside control
  149.         pIPCB->m_enCurrentState = igsFloatActive;
  150.         if(pIPCB->m_pfnVerb)
  151.             pIPCB->m_pfnVerb(vaDoVerb, NULL);
  152.     }
  153.     IP_Invalidate(hPart);
  154. }
  155. //
  156. //
  157. //