00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "RichFragment.h"
00025 #include "RichElement.h"
00026 #include "RichViewCtrl.h"
00027
00028 #include "CoolInterface.h"
00029 #include "Emoticons.h"
00030
00031 #ifdef _DEBUG
00032 #undef THIS_FILE
00033 static char THIS_FILE[]=__FILE__;
00034 #define new DEBUG_NEW
00035 #endif
00036
00037
00039
00040
00041 CRichFragment::CRichFragment(CRichElement* pElement, int nOffset, int nLength, CPoint* pPoint, CSize* pSize)
00042 {
00043 m_pElement = pElement;
00044 m_pt = *pPoint;
00045 m_sz = *pSize;
00046 m_nOffset = (WORD)nOffset;
00047 m_nLength = (WORD)nLength;
00048 }
00049
00050 CRichFragment::CRichFragment(CRichElement* pElement, CPoint* pPoint)
00051 {
00052 m_pElement = pElement;
00053 m_pt = *pPoint;
00054 m_sz = pElement->GetSize();
00055 m_nOffset = 0;
00056 m_nLength = 0;
00057 }
00058
00059 CRichFragment::~CRichFragment()
00060 {
00061 }
00062
00064
00065
00066 void CRichFragment::Add(int nLength, CSize* pSize)
00067 {
00068 ASSERT( m_pElement->m_nType >= retText );
00069
00070 m_nLength = nLength;
00071 m_sz = *pSize;
00072 }
00073
00075
00076
00077 void CRichFragment::Paint(CDC* pDC, CRichViewCtrl* pCtrl, int nFragment)
00078 {
00079 BOOL bClean = pCtrl->m_pSelAbsEnd.nFragment < nFragment ||
00080 pCtrl->m_pSelAbsStart.nFragment > nFragment;
00081 BOOL bSelect = FALSE;
00082
00083 if ( ! bClean )
00084 {
00085 if ( pCtrl->m_pSelAbsStart.nFragment == pCtrl->m_pSelAbsEnd.nFragment &&
00086 pCtrl->m_pSelAbsStart.nOffset == pCtrl->m_pSelAbsEnd.nOffset )
00087 {
00088 bClean = TRUE;
00089 }
00090 else if ( nFragment < pCtrl->m_pSelAbsEnd.nFragment &&
00091 ( nFragment > pCtrl->m_pSelAbsStart.nFragment ||
00092 nFragment == pCtrl->m_pSelAbsStart.nFragment &&
00093 0 == pCtrl->m_pSelAbsStart.nOffset ) )
00094 {
00095 bSelect = TRUE;
00096 }
00097 }
00098
00099 if ( m_pElement->m_nType >= retText )
00100 {
00101 LPCTSTR pszText = (LPCTSTR)m_pElement->m_sText + m_nOffset;
00102
00103 if ( bClean )
00104 {
00105 pDC->ExtTextOut( m_pt.x - ( theApp.m_bRTL ? 1 : 0 ), m_pt.y, ETO_OPAQUE,
00106 NULL, pszText, m_nLength, NULL );
00107 }
00108 else if ( bSelect )
00109 {
00110 pDC->SetBkColor( pDC->SetTextColor( pDC->GetBkColor() ) );
00111 pDC->ExtTextOut( m_pt.x, m_pt.y, ETO_OPAQUE, NULL, pszText, m_nLength, NULL );
00112 pDC->SetBkColor( pDC->SetTextColor( pDC->GetBkColor() ) );
00113 }
00114 else if ( pCtrl->m_pSelAbsStart.nFragment == nFragment ||
00115 pCtrl->m_pSelAbsEnd.nFragment == nFragment )
00116 {
00117 int nCharStart = 0, nCharEnd = m_nLength;
00118 int nX = m_pt.x;
00119
00120 if ( pCtrl->m_pSelAbsStart.nFragment == nFragment )
00121 {
00122 nCharStart = pCtrl->m_pSelAbsStart.nOffset;
00123 }
00124
00125 if ( pCtrl->m_pSelAbsEnd.nFragment == nFragment )
00126 {
00127 nCharEnd = pCtrl->m_pSelAbsEnd.nOffset;
00128 }
00129
00130 if ( nCharStart > 0 )
00131 {
00132 pDC->ExtTextOut( nX, m_pt.y, ETO_OPAQUE, NULL, pszText, nCharStart, NULL );
00133 nX += pDC->GetTextExtent( pszText, nCharStart ).cx;
00134 pszText += nCharStart;
00135 }
00136
00137 if ( nCharStart < nCharEnd )
00138 {
00139 pDC->SetBkColor( pDC->SetTextColor( pDC->GetBkColor() ) );
00140 pDC->ExtTextOut( nX, m_pt.y, ETO_OPAQUE, NULL, pszText, nCharEnd - nCharStart, NULL );
00141 pDC->SetBkColor( pDC->SetTextColor( pDC->GetBkColor() ) );
00142 nX += pDC->GetTextExtent( pszText, nCharEnd - nCharStart ).cx;
00143 pszText += nCharEnd - nCharStart;
00144 }
00145
00146 if ( nCharEnd < m_nLength )
00147 {
00148 pDC->ExtTextOut( nX, m_pt.y, ETO_OPAQUE, NULL, pszText, m_nLength - nCharEnd, NULL );
00149 }
00150 }
00151 else
00152 {
00153 pDC->ExtTextOut( m_pt.x, m_pt.y, ETO_OPAQUE, NULL, pszText, m_nLength, NULL );
00154 }
00155
00156 pDC->ExcludeClipRect( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00157 }
00158 else if ( m_pElement->m_nType == retBitmap && m_pElement->m_hImage )
00159 {
00160 CDC mdc;
00161 mdc.CreateCompatibleDC( pDC );
00162
00163 HBITMAP hOld = (HBITMAP)SelectObject( mdc.GetSafeHdc(),
00164 (HBITMAP)m_pElement->m_hImage );
00165
00166 pDC->BitBlt( m_pt.x, m_pt.y, m_sz.cx, m_sz.cy, &mdc, 0, 0, SRCCOPY );
00167
00168 SelectObject( mdc.GetSafeHdc(), hOld );
00169 mdc.DeleteDC();
00170
00171 if ( bSelect )
00172 {
00173 CRect rc( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00174 pDC->InvertRect( &rc );
00175 }
00176
00177 pDC->ExcludeClipRect( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00178 }
00179 else if ( m_pElement->m_nType == retIcon && m_pElement->m_hImage )
00180 {
00181 DrawIconEx( pDC->GetSafeHdc(), m_pt.x, m_pt.y, (HICON)m_pElement->m_hImage,
00182 m_sz.cx, m_sz.cy, 0, (HBRUSH)pCtrl->m_pBrush.GetSafeHandle(), DI_NORMAL );
00183
00184 if ( bSelect )
00185 {
00186 CRect rc( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00187 pDC->InvertRect( &rc );
00188 }
00189
00190 pDC->ExcludeClipRect( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00191 }
00192 else if ( m_pElement->m_nType == retEmoticon )
00193 {
00194 Emoticons.Draw( pDC, (int)m_pElement->m_hImage, m_pt.x, m_pt.y,
00195 pDC->GetBkColor() );
00196
00197 if ( bSelect )
00198 {
00199 CRect rc( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00200 pDC->InvertRect( &rc );
00201 }
00202
00203 pDC->ExcludeClipRect( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00204 }
00205 else if ( m_pElement->m_nType == retCmdIcon )
00206 {
00207 ImageList_DrawEx( CoolInterface.m_pImages, (int)m_pElement->m_hImage,
00208 *pDC, m_pt.x, m_pt.y, 16, 16, pDC->GetBkColor(), CLR_NONE, ILD_NORMAL );
00209
00210 if ( bSelect )
00211 {
00212 CRect rc( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00213 pDC->InvertRect( &rc );
00214 }
00215
00216 pDC->ExcludeClipRect( m_pt.x, m_pt.y, m_pt.x + m_sz.cx, m_pt.y + m_sz.cy );
00217 }
00218 }