diff options
Diffstat (limited to 'plugins/mTextControl/src/FormattedTextDraw.cpp')
-rw-r--r-- | plugins/mTextControl/src/FormattedTextDraw.cpp | 204 |
1 files changed, 88 insertions, 116 deletions
diff --git a/plugins/mTextControl/src/FormattedTextDraw.cpp b/plugins/mTextControl/src/FormattedTextDraw.cpp index 6555e8d0a0..6a9e2d2cdc 100644 --- a/plugins/mTextControl/src/FormattedTextDraw.cpp +++ b/plugins/mTextControl/src/FormattedTextDraw.cpp @@ -30,25 +30,25 @@ static const IID IID_ITextDocument = { /////////////////////////////////////////////////////////////////////////////
// CallBack functions
+
DWORD CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
- PCOOKIE pCookie = (PCOOKIE) dwCookie;
- if (pCookie->isUnicode)
- {
- if ((pCookie->dwSize - pCookie->dwCount)*sizeof(WCHAR) < (DWORD)cb)
- *pcb = (pCookie->dwSize - pCookie->dwCount)*sizeof(WCHAR);
+ COOKIE *pCookie = (COOKIE*)dwCookie;
+ if (pCookie->isUnicode) {
+ if ((pCookie->cbSize - pCookie->cbCount)*sizeof(WCHAR) < (size_t)cb)
+ *pcb = LONG(pCookie->cbSize - pCookie->cbCount)*sizeof(WCHAR);
else
- *pcb = cb&~1UL;
- CopyMemory(pbBuff, pCookie->unicode+pCookie->dwCount, *pcb);
- pCookie->dwCount += *pcb/sizeof(WCHAR);
- } else
- {
- if(pCookie->dwSize - pCookie->dwCount < (DWORD)cb)
- *pcb = pCookie->dwSize - pCookie->dwCount;
+ *pcb = cb & ~1UL;
+ CopyMemory(pbBuff, pCookie->unicode + pCookie->cbCount, *pcb);
+ pCookie->cbCount += *pcb / sizeof(WCHAR);
+ }
+ else {
+ if (pCookie->cbSize - pCookie->cbCount < (DWORD)cb)
+ *pcb = LONG(pCookie->cbSize - pCookie->cbCount);
else
*pcb = cb;
- CopyMemory(pbBuff, pCookie->ansi+pCookie->dwCount, *pcb);
- pCookie->dwCount += *pcb;
+ CopyMemory(pbBuff, pCookie->ansi + pCookie->cbCount, *pcb);
+ pCookie->cbCount += *pcb;
}
return 0; // callback succeeded - no errors
@@ -56,69 +56,69 @@ DWORD CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, /////////////////////////////////////////////////////////////////////////////
// CFormattedTextDraw
+
HRESULT CFormattedTextDraw::putRTFTextA(char *newVal)
{
- HRESULT hr;
- LRESULT lResult = 0;
- EDITSTREAM editStream;
-
- if (!m_spTextServices)
+ if (!m_spTextServices)
return S_FALSE;
m_editCookie.isUnicode = false;
m_editCookie.ansi = newVal;
- m_editCookie.dwSize = mir_strlen(m_editCookie.ansi);
- m_editCookie.dwCount = 0;
- editStream.dwCookie = (DWORD_PTR) &m_editCookie;
+ m_editCookie.cbSize = mir_strlen(m_editCookie.ansi);
+ m_editCookie.cbCount = 0;
+
+ EDITSTREAM editStream;
+ editStream.dwCookie = (DWORD_PTR)&m_editCookie;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
- hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_RTF), (LPARAM)&editStream, &lResult);
+
+ LRESULT lResult = 0;
+ HRESULT hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_RTF), (LPARAM)&editStream, &lResult);
return S_OK;
}
HRESULT CFormattedTextDraw::putRTFTextW(WCHAR *newVal)
{
-
- HRESULT hr;
- LRESULT lResult = 0;
- EDITSTREAM editStream;
-
- if (!m_spTextServices)
+ if (!m_spTextServices)
return S_FALSE;
m_editCookie.isUnicode = true;
m_editCookie.unicode = newVal;
- m_editCookie.dwSize = mir_wstrlen(m_editCookie.unicode);
- m_editCookie.dwCount = 0;
- editStream.dwCookie = (DWORD_PTR) &m_editCookie;
+ m_editCookie.cbSize = mir_wstrlen(m_editCookie.unicode);
+ m_editCookie.cbCount = 0;
+
+ EDITSTREAM editStream;
+ editStream.dwCookie = (DWORD_PTR)&m_editCookie;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
- hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_RTF|SF_UNICODE), (LPARAM)&editStream, &lResult);
+
+ LRESULT lResult = 0;
+ HRESULT hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_RTF | SF_UNICODE), (LPARAM)&editStream, &lResult);
return S_OK;
}
HRESULT CFormattedTextDraw::putTextA(char *newVal)
{
- HRESULT hr;
- LRESULT lResult = 0;
- EDITSTREAM editStream;
-
- if (!m_spTextServices)
+ if (!m_spTextServices)
return S_FALSE;
m_editCookie.isUnicode = false;
m_editCookie.ansi = newVal;
- m_editCookie.dwSize = mir_strlen(m_editCookie.ansi);
- m_editCookie.dwCount = 0;
- editStream.dwCookie = (DWORD_PTR) &m_editCookie;
+ m_editCookie.cbSize = mir_strlen(m_editCookie.ansi);
+ m_editCookie.cbCount = 0;
+
+ EDITSTREAM editStream;
+ editStream.dwCookie = (DWORD_PTR)&m_editCookie;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
- hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_TEXT), (LPARAM)&editStream, &lResult);
-
+
+ LRESULT lResult = 0;
+ HRESULT hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_TEXT), (LPARAM)&editStream, &lResult);
+
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
- cf.dwMask = CFM_FACE|CFM_BOLD;
+ cf.dwMask = CFM_FACE | CFM_BOLD;
cf.dwEffects = 0;
mir_sntprintf(cf.szFaceName, SIZEOF(cf.szFaceName), _T("MS Shell Dlg"));
m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
@@ -128,32 +128,29 @@ HRESULT CFormattedTextDraw::putTextA(char *newVal) HRESULT CFormattedTextDraw::putTextW(WCHAR *newVal)
{
-
- HRESULT hr;
- LRESULT lResult = 0;
- EDITSTREAM editStream;
-
- if (!m_spTextServices)
+ if (!m_spTextServices)
return S_FALSE;
m_editCookie.isUnicode = true;
m_editCookie.unicode = newVal;
- m_editCookie.dwSize = mir_wstrlen(m_editCookie.unicode);
- m_editCookie.dwCount = 0;
- editStream.dwCookie = (DWORD_PTR) &m_editCookie;
+ m_editCookie.cbSize = mir_wstrlen(m_editCookie.unicode);
+ m_editCookie.cbCount = 0;
+
+ EDITSTREAM editStream;
+ editStream.dwCookie = (DWORD_PTR)&m_editCookie;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
- hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_TEXT|SF_UNICODE), (LPARAM)&editStream, &lResult);
-
+
+ LRESULT lResult = 0;
+ HRESULT hr = m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_TEXT | SF_UNICODE), (LPARAM)&editStream, &lResult);
+
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
- cf.dwMask = CFM_FACE|CFM_BOLD;
+ cf.dwMask = CFM_FACE | CFM_BOLD;
cf.dwEffects = 0;
mir_sntprintf(cf.szFaceName, SIZEOF(cf.szFaceName), _T("MS Shell Dlg"));
m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
-
return S_OK;
-
}
HRESULT CFormattedTextDraw::Draw(void *hdcDraw, RECT *prc)
@@ -164,12 +161,12 @@ HRESULT CFormattedTextDraw::Draw(void *hdcDraw, RECT *prc) LRESULT lResult;
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
- cf.dwMask = CFM_FACE/*|CFM_COLOR*/|CFM_CHARSET|CFM_SIZE|
- (lf.lfWeight>=FW_BOLD?CFM_BOLD:0)|
- (lf.lfItalic?CFM_ITALIC:0)|
- (lf.lfUnderline?CFM_UNDERLINE:0)|
- (lf.lfStrikeOut?CFM_STRIKEOUT:0);
- cf.dwEffects = CFE_BOLD|CFE_ITALIC|CFE_STRIKEOUT|CFE_UNDERLINE;
+ cf.dwMask = CFM_FACE/*|CFM_COLOR*/ | CFM_CHARSET | CFM_SIZE |
+ (lf.lfWeight >= FW_BOLD ? CFM_BOLD : 0) |
+ (lf.lfItalic ? CFM_ITALIC : 0) |
+ (lf.lfUnderline ? CFM_UNDERLINE : 0) |
+ (lf.lfStrikeOut ? CFM_STRIKEOUT : 0);
+ cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE;
cf.crTextColor = GetTextColor((HDC)hdcDraw);
cf.bCharSet = lf.lfCharSet;
cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY);
@@ -177,15 +174,15 @@ HRESULT CFormattedTextDraw::Draw(void *hdcDraw, RECT *prc) m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
m_spTextServices->TxDraw(
- DVASPECT_CONTENT, // Draw Aspect
+ DVASPECT_CONTENT, // Draw Aspect
0, // Lindex
NULL, // Info for drawing optimization
NULL, // target device information
- (HDC) hdcDraw, // Draw device HDC
+ (HDC)hdcDraw, // Draw device HDC
NULL, // Target device HDC
- (RECTL *) prc, // Bounding client rectangle
+ (RECTL *)prc, // Bounding client rectangle
NULL, // Clipping rectangle for metafiles
- (RECT *) NULL, // Update rectangle
+ (RECT *)NULL, // Update rectangle
NULL, // Call back function
NULL, // Call back parameter
TXTVIEW_INACTIVE); // What view of the object could be TXTVIEW_ACTIVE
@@ -205,12 +202,12 @@ HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *He LRESULT lResult;
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
- cf.dwMask = CFM_FACE/*|CFM_COLOR*/|CFM_CHARSET|CFM_SIZE|
- (lf.lfWeight>=FW_BOLD?CFM_BOLD:0)|
- (lf.lfItalic?CFM_ITALIC:0)|
- (lf.lfUnderline?CFM_UNDERLINE:0)|
- (lf.lfStrikeOut?CFM_STRIKEOUT:0);
- cf.dwEffects = CFE_BOLD|CFE_ITALIC|CFE_STRIKEOUT|CFE_UNDERLINE;
+ cf.dwMask = CFM_FACE/*|CFM_COLOR*/ | CFM_CHARSET | CFM_SIZE |
+ (lf.lfWeight >= FW_BOLD ? CFM_BOLD : 0) |
+ (lf.lfItalic ? CFM_ITALIC : 0) |
+ (lf.lfUnderline ? CFM_UNDERLINE : 0) |
+ (lf.lfStrikeOut ? CFM_STRIKEOUT : 0);
+ cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE;
cf.crTextColor = GetTextColor((HDC)hdcDraw);
cf.bCharSet = lf.lfCharSet;
cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY);
@@ -221,24 +218,20 @@ HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *He m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
- SIZEL szExtent;
-// HDC hdcDraw;
-// hdcDraw = GetDC(NULL);
*Height = 1;
+
+ SIZEL szExtent;
szExtent.cx = *Width;
szExtent.cy = *Height;
if (m_spTextServices->TxGetNaturalSize(DVASPECT_CONTENT, (HDC)hdcDraw, NULL, NULL, TXTNS_FITTOCONTENT, &szExtent, Width, Height) != S_OK)
- {
-// ReleaseDC(NULL, hdcDraw);
return S_FALSE;
- }
-// ReleaseDC(NULL, hdcDraw);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
// ITextHost functions
+
HDC CFormattedTextDraw::TxGetDC()
{
return NULL;
@@ -270,12 +263,10 @@ BOOL CFormattedTextDraw::TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw) }
void CFormattedTextDraw::TxInvalidateRect(LPCRECT prc, BOOL fMode)
-{
-}
+{}
void CFormattedTextDraw::TxViewChange(BOOL fUpdate)
-{
-}
+{}
BOOL CFormattedTextDraw::TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight)
{
@@ -313,33 +304,26 @@ void CFormattedTextDraw::TxSetFocus() {
}
-
void CFormattedTextDraw::TxSetCursor(HCURSOR hcur, BOOL fText)
{
if (fText)
- {
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
- } else
- {
+ else
SetCursor(hcur);
- }
}
BOOL CFormattedTextDraw::TxScreenToClient(LPPOINT lppt)
{
if (!m_hwndParent) return FALSE;
-// BOOL result = ScreenToClient(m_hwndParent, lppt);
-// lppt->x -= m_rcClient.left;
-// lppt->y -= m_rcClient.left;
return ScreenToClient(m_hwndParent, lppt);
}
BOOL CFormattedTextDraw::TxClientToScreen(LPPOINT lppt)
{
if (!m_hwndParent) return FALSE;
-// BOOL result = ;
-// lppt->x -= m_rcClient.left;
-// lppt->y -= m_rcClient.left;
+ // BOOL result = ;
+ // lppt->x -= m_rcClient.left;
+ // lppt->y -= m_rcClient.left;
return ClientToScreen(m_hwndParent, lppt);
}
@@ -445,8 +429,7 @@ HIMC CFormattedTextDraw::TxImmGetContext() }
void CFormattedTextDraw::TxImmReleaseContext(HIMC himc)
-{
-}
+{}
HRESULT CFormattedTextDraw::TxGetSelectionBarWidth(LONG *lSelBarWidth)
{
@@ -460,17 +443,12 @@ HRESULT CFormattedTextDraw::TxGetSelectionBarWidth(LONG *lSelBarWidth) HRESULT CFormattedTextDraw::CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont)
// Takes an HFONT and fills in a CHARFORMAT2W structure with the corresponding info
{
-
- HWND hWnd;
- LOGFONT lf;
- HDC hDC;
- LONG yPixPerInch;
-
// Get LOGFONT for default font
if (!hFont)
- hFont = (HFONT) GetStockObject(SYSTEM_FONT);
+ hFont = (HFONT)GetStockObject(SYSTEM_FONT);
// Get LOGFONT for passed hfont
+ LOGFONT lf;
if (!GetObject(hFont, sizeof(LOGFONT), &lf))
return E_FAIL;
@@ -478,9 +456,9 @@ HRESULT CFormattedTextDraw::CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont) memset(pCF, 0, sizeof(CHARFORMAT2W));
pCF->cbSize = sizeof(CHARFORMAT2W);
- hWnd = GetDesktopWindow();
- hDC = GetDC(hWnd);
- yPixPerInch = GetDeviceCaps(hDC, LOGPIXELSY);
+ HWND hWnd = GetDesktopWindow();
+ HDC hDC = GetDC(hWnd);
+ LONG yPixPerInch = GetDeviceCaps(hDC, LOGPIXELSY);
pCF->yHeight = -lf.lfHeight * LY_PER_INCH / yPixPerInch;
ReleaseDC(hWnd, hDC);
@@ -490,7 +468,7 @@ HRESULT CFormattedTextDraw::CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont) pCF->dwEffects = CFM_EFFECTS | CFE_AUTOBACKCOLOR;
pCF->dwEffects &= ~(CFE_PROTECTED | CFE_LINK | CFE_AUTOCOLOR);
- if(lf.lfWeight < FW_BOLD)
+ if (lf.lfWeight < FW_BOLD)
pCF->dwEffects &= ~CFE_BOLD;
if (!lf.lfItalic)
@@ -506,10 +484,7 @@ HRESULT CFormattedTextDraw::CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont) pCF->bCharSet = lf.lfCharSet;
pCF->bPitchAndFamily = lf.lfPitchAndFamily;
-
mir_wstrcpy(pCF->szFaceName, lf.lfFaceName);
-
-
return S_OK;
}
@@ -531,10 +506,8 @@ HRESULT CFormattedTextDraw::InitDefaultParaFormat() HRESULT CFormattedTextDraw::CreateTextServicesObject()
{
- HRESULT hr;
IUnknown *spUnk;
-
- hr = MyCreateTextServices(NULL, static_cast<ITextHost*>(this), &spUnk);
+ HRESULT hr = MyCreateTextServices(NULL, static_cast<ITextHost*>(this), &spUnk);
if (hr == S_OK) {
hr = spUnk->QueryInterface(IID_ITextServices, (void**)&m_spTextServices);
hr = spUnk->QueryInterface(IID_ITextDocument, (void**)&m_spTextDocument);
@@ -542,4 +515,3 @@ HRESULT CFormattedTextDraw::CreateTextServicesObject() }
return hr;
}
-
|