ISkinControl.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #include "StdAfx.h"
  2. #include "ISkinControl.h"
  3. ISkinControl::ISkinControl(void)
  4. {
  5. m_hParentDC = NULL;
  6. m_bTransparent = FALSE;
  7. m_colDefText = RGB(128,128,128);
  8. m_colNormalText = RGB(0,0,0);
  9. m_colDisableText = RGB(128,128,128);
  10. m_colReadOnlyText = RGB(0,0,0);
  11. m_colSelectText = RGB(255,255,255);
  12. m_colFrameNormal = RGB(0,0,0);
  13. m_colBack=RGB(255,255,255);
  14. m_Font = RenderEngine->GetDeaultFont();
  15. m_dwTextAlign = 0;
  16. m_pOwnWnd = NULL;
  17. m_ptPosition.SetPoint(0,0);
  18. m_szSize.SetSize(0,0);
  19. m_FixedPostion[0] = m_FixedPostion[1] = en_LTop;
  20. }
  21. ISkinControl::~ISkinControl(void)
  22. {
  23. m_bTransparent = FALSE;
  24. }
  25. void ISkinControl::CalcCenterRect( RECT& rcDest, int cx, int cy, RECT& rcCenter )
  26. {
  27. int x = ((rcDest.right-rcDest.left) - cx + 1) / 2;
  28. int y = ((rcDest.bottom-rcDest.top) - cy + 1) / 2;
  29. rcCenter.left = rcDest.left+x;
  30. rcCenter.top = rcDest.top+y;
  31. rcCenter.right = rcCenter.left+cx;
  32. rcCenter.bottom = rcCenter.top+cy;
  33. }
  34. void ISkinControl::DrawParentWndBg(HWND hWnd, HDC hDC )
  35. {
  36. if( hWnd == NULL ) return;
  37. if ( !m_bTransparent ) return;
  38. HWND hParentWnd = ::GetParent(hWnd);
  39. CRect rcWindow;
  40. ::GetWindowRect(hWnd,&rcWindow);
  41. ::ScreenToClient(hParentWnd, (LPPOINT)&rcWindow);
  42. ::ScreenToClient(hParentWnd, ((LPPOINT)&rcWindow)+1);
  43. ::BitBlt(hDC, 0, 0, rcWindow.Width(), rcWindow.Height(), m_hParentDC, rcWindow.left, rcWindow.top, SRCCOPY);
  44. }
  45. void ISkinControl::SetDefText( COLORREF colText )
  46. {
  47. m_colDefText = colText;
  48. }
  49. void ISkinControl::SetNormalText( COLORREF colText )
  50. {
  51. m_colNormalText = colText;
  52. }
  53. void ISkinControl::SetDisableText( COLORREF colText )
  54. {
  55. m_colDisableText = colText;
  56. }
  57. void ISkinControl::SetSelectText( COLORREF colText )
  58. {
  59. m_colSelectText = colText;
  60. }
  61. void ISkinControl::SetFrameColor( COLORREF colFrame )
  62. {
  63. m_colFrameNormal = colFrame;
  64. }
  65. BOOL ISkinControl::SetScrollImage( CWnd * pOwn,LPCTSTR pszFileName )
  66. {
  67. RenderEngine->RemoveImage(m_pImageScroll);
  68. m_pImageScroll = RenderEngine->GetImage(pszFileName);
  69. if ( (m_pImageScroll != NULL) && (pOwn != NULL) && (pOwn->GetSafeHwnd() != NULL) )
  70. {
  71. ASSERT(m_pImageScroll != NULL);
  72. if( m_pImageScroll == NULL) return FALSE;
  73. //ÉèÖùö¶¯
  74. SkinUI_Init(pOwn->GetSafeHwnd(),m_pImageScroll->ImageToBitmap());
  75. }
  76. return TRUE;
  77. }
  78. void ISkinControl::RemoveScorll()
  79. {
  80. RenderEngine->RemoveImage(m_pImageScroll);
  81. }
  82. BOOL ISkinControl::TrackMouseLeave( HWND hWnd )
  83. {
  84. TRACKMOUSEEVENT tme = { 0 };
  85. tme.cbSize = sizeof(tme);
  86. tme.dwFlags = TME_LEAVE;
  87. tme.hwndTrack = hWnd;
  88. return _TrackMouseEvent(&tme);
  89. }
  90. void ISkinControl::SetCtrlFont( HFONT hFont )
  91. {
  92. m_Font = hFont;
  93. }
  94. HFONT ISkinControl::GetCtrlFont()
  95. {
  96. return m_Font;
  97. }
  98. void ISkinControl::SetBackColor( COLORREF colBack )
  99. {
  100. m_colBack = colBack;
  101. }
  102. void ISkinControl::SetUnTransparent()
  103. {
  104. m_bTransparent = false;
  105. }
  106. void ISkinControl::SetTextAlign( WORD wTextAlign )
  107. {
  108. m_dwTextAlign = wTextAlign;
  109. }
  110. void ISkinControl::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
  111. {
  112. if ( m_pOwnWnd == NULL ) return;
  113. LPTSTR pstr = NULL;
  114. if( _tcscmp(pstrName, _T("text")) == 0 ) m_pOwnWnd->SetWindowText(pstrValue);
  115. if( _tcscmp(pstrName, _T("id")) == 0 ) m_pOwnWnd->SetDlgCtrlID(_ttoi(pstrValue));
  116. else if( _tcscmp(pstrName, _T("show")) == 0 ){ m_pOwnWnd->ShowWindow((_tcscmp(pstrValue, _T("true")) == 0) ? SW_SHOW : SW_HIDE); }
  117. else if( _tcscmp(pstrName, _T("enable")) == 0 ){ m_pOwnWnd->EnableWindow((_tcscmp(pstrValue, _T("true")) == 0) ? TRUE : FALSE); }
  118. else if( _tcscmp(pstrName, _T("pos")) == 0 )
  119. {
  120. LPTSTR pstr = NULL;
  121. m_FixedPostion[0] = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  122. m_FixedPostion[1] = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  123. m_ptPosition.x = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  124. m_ptPosition.y = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  125. m_szSize.cx = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  126. m_szSize.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  127. }
  128. else if( _tcscmp(pstrName, _T("trans")) == 0 ){ m_bTransparent = (_tcscmp(pstrValue, _T("true")) == 0) ? TRUE : FALSE; }
  129. else if( _tcscmp(pstrName, _T("fontdefaultcolor")) == 0 )
  130. {
  131. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  132. m_colDefText = _tcstoul(pstrValue, &pstr, 16);
  133. }
  134. else if( _tcscmp(pstrName, _T("fontnormalcolor")) == 0 )
  135. {
  136. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  137. m_colNormalText = _tcstoul(pstrValue, &pstr, 16);
  138. }
  139. else if( _tcscmp(pstrName, _T("fontselcolor")) == 0 )
  140. {
  141. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  142. m_colSelectText = _tcstoul(pstrValue, &pstr, 16);
  143. }
  144. else if( _tcscmp(pstrName, _T("fontdiscolor")) == 0 )
  145. {
  146. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  147. m_colDisableText = _tcstoul(pstrValue, &pstr, 16);
  148. }
  149. else if( _tcscmp(pstrName, _T("fontreadonlycolor")) == 0 )
  150. {
  151. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  152. m_colReadOnlyText = _tcstoul(pstrValue, &pstr, 16);
  153. }
  154. else if( _tcscmp(pstrName, _T("bkcolor")) == 0 )
  155. {
  156. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  157. m_colBack = _tcstoul(pstrValue, &pstr, 16);
  158. }
  159. }