WndPureTextBtn.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:5k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面窗口体系结构-纯文字按钮
  3. // Copyright : Kingsoft 2003
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2003-1-19
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../Elem/WndMessage.h"
  10. #include "WndPureTextBtn.h"
  11. #include "Text.h"
  12. #include "../../../Represent/iRepresent/iRepresentShell.h"
  13. extern iRepresentShell* g_pRepresentShell;
  14. KWndPureTextBtn::KWndPureTextBtn()
  15. {
  16. m_Flag = 0;
  17. m_sText[0] = 0;
  18. m_nTextLen = 0;
  19. m_nFontSize = 12;
  20. m_NormalColor = m_OverColor = m_PressedColor = 0;
  21. m_NormalBorderColor = m_OverBorderColor = m_PressedBorderColor = 0;
  22. }
  23. void KWndPureTextBtn::Clone(KWndPureTextBtn* pCopy)
  24. {
  25. if (pCopy)
  26. {
  27. KWndWindow::Clone(pCopy);
  28. pCopy->m_NormalColor = m_NormalColor;
  29. pCopy->m_OverColor = m_OverColor;
  30. pCopy->m_PressedColor = m_PressedColor;
  31. pCopy->m_nFontSize = m_nFontSize;
  32. pCopy->m_NormalBorderColor = m_NormalBorderColor;
  33. pCopy->m_OverBorderColor = m_OverBorderColor;
  34. pCopy->m_PressedBorderColor = m_PressedBorderColor;
  35. }
  36. }
  37. int KWndPureTextBtn::Init(KIniFile* pIniFile, const char* pSection)
  38. {
  39. if (KWndWindow::Init(pIniFile, pSection))
  40. {
  41. pIniFile->GetInteger(pSection, "Font", 12, &m_nFontSize);
  42. if (m_nFontSize < 8)
  43. m_nFontSize = 8;
  44. int nValue;
  45. pIniFile->GetInteger(pSection, "CentreAlign", 1, &nValue);
  46. if (nValue)
  47. m_Style |= WNDPTB_S_CENTRE_ALIGN;
  48. else
  49. m_Style &= ~WNDPTB_S_CENTRE_ALIGN;
  50. char Buff[16];
  51. pIniFile->GetString(pSection, "Color", "", Buff, sizeof(Buff));
  52. m_NormalColor = GetColor(Buff);
  53. pIniFile->GetString(pSection, "BorderColor", "0,0,0", Buff, 16);
  54. m_NormalBorderColor = GetColor(Buff);
  55. pIniFile->GetString(pSection, "OverColor", "", Buff, sizeof(Buff));
  56. m_OverColor = GetColor(Buff);
  57. pIniFile->GetString(pSection, "OverBorderColor", "0,0,0", Buff, 16);
  58. m_OverBorderColor = GetColor(Buff);
  59. pIniFile->GetString(pSection, "SelColor", "", Buff, sizeof(Buff));
  60. m_PressedColor = GetColor(Buff);
  61. pIniFile->GetString(pSection, "SelBorderColor", "0,0,0", Buff, 16);
  62. m_PressedBorderColor = GetColor(Buff);
  63. // AdjustPosition();
  64. }
  65. return false;
  66. }
  67. void KWndPureTextBtn::AdjustPosition()
  68. {
  69. int nTextWidth = m_nTextLen * m_nFontSize / 2;
  70. if (m_Style & WNDPTB_S_CENTRE_ALIGN)
  71. SetPosition(m_Left + (m_Width - nTextWidth) / 2, m_Top);
  72. SetSize(nTextWidth, m_Height);
  73. }
  74. //绘制窗口
  75. void KWndPureTextBtn::PaintWindow()
  76. {
  77. KWndWindow::PaintWindow();
  78. if (m_sText == NULL || m_sText[0] == 0 || g_pRepresentShell == NULL)
  79. return;
  80. KOutputTextParam param;
  81. if (m_Flag & WNDPTB_F_BE_PRESSEDDOWN ||
  82. m_Flag & WNDPTB_F_CHECK)
  83. {
  84. param.Color = m_PressedColor;
  85. param.BorderColor = m_PressedBorderColor;
  86. }
  87. else if (m_Flag & WNDPTB_F_OVER)
  88. {
  89. param.Color = m_OverColor;
  90. param.BorderColor = m_OverBorderColor;
  91. }
  92. else
  93. {
  94. param.Color = m_NormalColor;
  95. param.BorderColor = m_NormalBorderColor;
  96. }
  97. param.nX = m_nAbsoluteLeft + (m_Width - m_nTextLen * m_nFontSize / 2) / 2;
  98. param.nY = m_nAbsoluteTop;
  99. param.nZ = TEXT_IN_SINGLE_PLANE_COORD;
  100. param.nSkipLine = 0;
  101. param.nNumLine = 100;
  102. g_pRepresentShell->OutputRichText(m_nFontSize, &param, m_sText, m_nTextLen);
  103. }
  104. //设置文本文字
  105. void KWndPureTextBtn::SetText(const char* pText, int nLen)
  106. {
  107. if (pText == NULL)
  108. nLen = 0;
  109. else if (nLen < 0)
  110. nLen = strlen(pText);
  111. if (nLen <= WNDPTB_MAX_TEXT_LEN)
  112. m_nTextLen = nLen;
  113. else
  114. m_nTextLen = WNDPTB_MAX_TEXT_LEN;
  115. if (m_nTextLen > 0)
  116. memcpy(m_sText, pText, m_nTextLen);
  117. // AdjustPosition();
  118. }
  119. void KWndPureTextBtn::CheckButton(int bChecked)
  120. {
  121. if (bChecked)
  122. m_Flag |= WNDPTB_F_CHECK;
  123. else
  124. m_Flag &= ~WNDPTB_F_CHECK;
  125. }
  126. //--------------------------------------------------------------------------
  127. // 功能:窗口函数(处理消息)
  128. //--------------------------------------------------------------------------
  129. int KWndPureTextBtn::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  130. {
  131. if (IsDisable())
  132. return KWndWindow::WndProc(uMsg, uParam, nParam);
  133. switch(uMsg)
  134. {
  135. case WM_LBUTTONUP:
  136. if (m_Flag & WNDPTB_F_BE_PRESSEDDOWN)
  137. {
  138. m_Flag &= ~WNDPTB_F_BE_PRESSEDDOWN;
  139. if (m_pParentWnd)
  140. m_pParentWnd->WndProc(WND_N_BUTTON_CLICK,
  141. (unsigned int)(KWndWindow*)this, 0);
  142. }
  143. break;
  144. case WM_LBUTTONDOWN:
  145. m_Flag |= WNDPTB_F_BE_PRESSEDDOWN;
  146. break;
  147. case WM_MOUSEMOVE:
  148. m_Flag |= WNDPTB_F_OVER;
  149. break;
  150. case WND_M_MOUSE_LEAVE:
  151. m_Flag &= ~WNDPTB_F_OVER;
  152. m_Flag &= ~WNDPTB_F_BE_PRESSEDDOWN;
  153. KWndWindow::WndProc(uMsg, uParam, nParam);
  154. break;
  155. default:
  156. return KWndWindow::WndProc(uMsg, uParam, nParam);
  157. }
  158. return 0;
  159. }