diff options
author | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-05-15 10:38:20 +0000 |
---|---|---|
committer | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-05-15 10:38:20 +0000 |
commit | 48540940b6c28bb4378abfeb500ec45a625b37b6 (patch) | |
tree | 2ef294c0763e802f91d868bdef4229b6868527de /plugins/mTextControl/src | |
parent | 5c350913f011e119127baeb32a6aedeb4f0d33bc (diff) |
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/mTextControl/src')
-rw-r--r-- | plugins/mTextControl/src/FormattedTextDraw.cpp | 551 | ||||
-rw-r--r-- | plugins/mTextControl/src/FormattedTextDraw.h | 193 | ||||
-rw-r--r-- | plugins/mTextControl/src/ImageDataObjectHlp.cpp | 252 | ||||
-rw-r--r-- | plugins/mTextControl/src/ImageDataObjectHlp.h | 32 | ||||
-rw-r--r-- | plugins/mTextControl/src/dataobject.cpp | 290 | ||||
-rw-r--r-- | plugins/mTextControl/src/enumformat.cpp | 232 | ||||
-rw-r--r-- | plugins/mTextControl/src/fancy_rtf.cpp | 179 | ||||
-rw-r--r-- | plugins/mTextControl/src/fancy_rtf.h | 6 | ||||
-rw-r--r-- | plugins/mTextControl/src/headers.h | 125 | ||||
-rw-r--r-- | plugins/mTextControl/src/main.cpp | 143 | ||||
-rw-r--r-- | plugins/mTextControl/src/richeditutils.cpp | 164 | ||||
-rw-r--r-- | plugins/mTextControl/src/richeditutils.h | 12 | ||||
-rw-r--r-- | plugins/mTextControl/src/services.cpp | 382 | ||||
-rw-r--r-- | plugins/mTextControl/src/services.h | 36 | ||||
-rw-r--r-- | plugins/mTextControl/src/textcontrol.cpp | 200 | ||||
-rw-r--r-- | plugins/mTextControl/src/textcontrol.h | 25 | ||||
-rw-r--r-- | plugins/mTextControl/src/textusers.cpp | 88 | ||||
-rw-r--r-- | plugins/mTextControl/src/textusers.h | 47 | ||||
-rw-r--r-- | plugins/mTextControl/src/version.h | 60 |
19 files changed, 3017 insertions, 0 deletions
diff --git a/plugins/mTextControl/src/FormattedTextDraw.cpp b/plugins/mTextControl/src/FormattedTextDraw.cpp new file mode 100644 index 0000000000..0762e779e9 --- /dev/null +++ b/plugins/mTextControl/src/FormattedTextDraw.cpp @@ -0,0 +1,551 @@ +// Feel free to use this code in your own applications.
+// The Author does not guarantee anything about this code.
+// Author : Yves Maurer
+
+// FormattedTextDraw.cpp : Implementation of CFormattedTextDraw
+
+#include "headers.h"
+
+
+const IID IID_ITextServices = { // 8d33f740-cf58-11ce-a89d-00aa006cadc5
+ 0x8d33f740,
+ 0xcf58,
+ 0x11ce,
+ {0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5}
+ };
+
+const IID IID_ITextHost = { // c5bdd8d0-d26e-11ce-a89e-00aa006cadc5
+ 0xc5bdd8d0,
+ 0xd26e,
+ 0x11ce,
+ {0xa8, 0x9e, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5}
+ };
+
+static const IID IID_ITextDocument = {
+ 0x8CC497C0,
+ 0xA1DF,
+ 0x11CE,
+ {0x80,0x98,0x00,0xAA,0x00,0x47,0xBE,0x5D}
+ };
+
+/////////////////////////////////////////////////////////////////////////////
+// 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);
+ 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;
+ else
+ *pcb = cb;
+ CopyMemory(pbBuff, pCookie->ansi+pCookie->dwCount, *pcb);
+ pCookie->dwCount += *pcb;
+ }
+
+ return 0; // callback succeeded - no errors
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// CFormattedTextDraw
+HRESULT CFormattedTextDraw::putRTFTextA(char *newVal)
+{
+ HRESULT hr;
+ LRESULT lResult = 0;
+ EDITSTREAM editStream;
+
+ if (!m_spTextServices)
+ return S_FALSE;
+
+ m_editCookie.isUnicode = false;
+ m_editCookie.ansi = newVal;
+ m_editCookie.dwSize = lstrlenA(m_editCookie.ansi);
+ m_editCookie.dwCount = 0;
+ 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);
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::putRTFTextW(WCHAR *newVal)
+{
+#ifdef UNICODE
+ HRESULT hr;
+ LRESULT lResult = 0;
+ EDITSTREAM editStream;
+
+ if (!m_spTextServices)
+ return S_FALSE;
+
+ m_editCookie.isUnicode = true;
+ m_editCookie.unicode = newVal;
+ m_editCookie.dwSize = lstrlenW(m_editCookie.unicode);
+ m_editCookie.dwCount = 0;
+ 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);
+ return S_OK;
+#else
+ return E_FAIL;
+#endif
+}
+
+HRESULT CFormattedTextDraw::putTextA(char *newVal)
+{
+ HRESULT hr;
+ LRESULT lResult = 0;
+ EDITSTREAM editStream;
+
+ if (!m_spTextServices)
+ return S_FALSE;
+
+ m_editCookie.isUnicode = false;
+ m_editCookie.ansi = newVal;
+ m_editCookie.dwSize = lstrlenA(m_editCookie.ansi);
+ m_editCookie.dwCount = 0;
+ 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);
+
+ CHARFORMAT cf;
+ cf.cbSize = sizeof(cf);
+ cf.dwMask = CFM_FACE|CFM_BOLD;
+ cf.dwEffects = 0;
+ wsprintf(cf.szFaceName, _T("MS Shell Dlg"));
+ m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
+
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::putTextW(WCHAR *newVal)
+{
+#ifdef UNICODE
+ HRESULT hr;
+ LRESULT lResult = 0;
+ EDITSTREAM editStream;
+
+ if (!m_spTextServices)
+ return S_FALSE;
+
+ m_editCookie.isUnicode = true;
+ m_editCookie.unicode = newVal;
+ m_editCookie.dwSize = lstrlenW(m_editCookie.unicode);
+ m_editCookie.dwCount = 0;
+ 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);
+
+ CHARFORMAT cf;
+ cf.cbSize = sizeof(cf);
+ cf.dwMask = CFM_FACE|CFM_BOLD;
+ cf.dwEffects = 0;
+ wsprintf(cf.szFaceName, _T("MS Shell Dlg"));
+ m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
+
+ return S_OK;
+#else
+ return E_FAIL;
+#endif
+}
+
+HRESULT CFormattedTextDraw::Draw(void *hdcDraw, RECT *prc)
+{
+ LOGFONT lf;
+ GetObject(GetCurrentObject((HDC)hdcDraw, OBJ_FONT), sizeof(lf), &lf);
+
+ 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.crTextColor = GetTextColor((HDC)hdcDraw);
+ cf.bCharSet = lf.lfCharSet;
+ cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY);
+ wsprintf(cf.szFaceName, lf.lfFaceName);
+ m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
+
+ m_spTextServices->TxDraw(
+ DVASPECT_CONTENT, // Draw Aspect
+ 0, // Lindex
+ NULL, // Info for drawing optimization
+ NULL, // target device information
+ (HDC) hdcDraw, // Draw device HDC
+ NULL, // Target device HDC
+ (RECTL *) prc, // Bounding client rectangle
+ NULL, // Clipping rectangle for metafiles
+ (RECT *) NULL, // Update rectangle
+ NULL, // Call back function
+ NULL, // Call back parameter
+ TXTVIEW_INACTIVE); // What view of the object could be TXTVIEW_ACTIVE
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::Create()
+{
+ return CreateTextServicesObject();
+}
+
+HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *Height)
+{
+ LOGFONT lf;
+ GetObject(GetCurrentObject((HDC)hdcDraw, OBJ_FONT), sizeof(lf), &lf);
+
+ 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.crTextColor = GetTextColor((HDC)hdcDraw);
+ cf.bCharSet = lf.lfCharSet;
+ cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY);
+ wsprintf(cf.szFaceName, lf.lfFaceName);
+ m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
+
+ SIZEL szExtent;
+// HDC hdcDraw;
+
+ if (!m_spTextServices)
+ return S_FALSE;
+
+// hdcDraw = GetDC(NULL);
+ *Height = 1;
+ 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;
+}
+
+INT CFormattedTextDraw::TxReleaseDC(HDC hdc)
+{
+ return 1;
+}
+
+BOOL CFormattedTextDraw::TxShowScrollBar(INT fnBar, BOOL fShow)
+{
+ return FALSE;
+}
+
+BOOL CFormattedTextDraw::TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags)
+{
+ return FALSE;
+}
+
+BOOL CFormattedTextDraw::TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw)
+{
+ return FALSE;
+}
+
+BOOL CFormattedTextDraw::TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw)
+{
+ return FALSE;
+}
+
+void CFormattedTextDraw::TxInvalidateRect(LPCRECT prc, BOOL fMode)
+{
+}
+
+void CFormattedTextDraw::TxViewChange(BOOL fUpdate)
+{
+}
+
+BOOL CFormattedTextDraw::TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight)
+{
+ return FALSE;
+}
+
+BOOL CFormattedTextDraw::TxShowCaret(BOOL fShow)
+{
+ return FALSE;
+}
+
+BOOL CFormattedTextDraw::TxSetCaretPos(INT x, INT y)
+{
+ return FALSE;
+}
+
+BOOL CFormattedTextDraw::TxSetTimer(UINT idTimer, UINT uTimeout)
+{
+ return FALSE;
+}
+
+void CFormattedTextDraw::TxKillTimer(UINT idTimer)
+{
+}
+
+void CFormattedTextDraw::TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll)
+{
+}
+
+void CFormattedTextDraw::TxSetCapture(BOOL fCapture)
+{
+}
+
+void CFormattedTextDraw::TxSetFocus()
+{
+}
+
+
+void CFormattedTextDraw::TxSetCursor(HCURSOR hcur, BOOL fText)
+{
+ if (fText)
+ {
+ SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
+ } 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;
+ return ClientToScreen(m_hwndParent, lppt);
+}
+
+HRESULT CFormattedTextDraw::TxActivate(LONG * plOldState)
+{
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxDeactivate(LONG lNewState)
+{
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetClientRect(LPRECT prc)
+{
+ *prc = m_rcClient;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetViewInset(LPRECT prc)
+{
+ *prc = m_rcViewInset;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetCharFormat(const CHARFORMATW **ppCF)
+{
+ *ppCF = m_pCF;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetParaFormat(const PARAFORMAT **ppPF)
+{
+ *ppPF = &m_PF;
+ return S_OK;
+}
+
+COLORREF CFormattedTextDraw::TxGetSysColor(int nIndex)
+{
+ return GetSysColor(nIndex);
+}
+
+HRESULT CFormattedTextDraw::TxGetBackStyle(TXTBACKSTYLE *pstyle)
+{
+ *pstyle = TXTBACK_TRANSPARENT;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetMaxLength(DWORD *plength)
+{
+ *plength = m_dwMaxLength;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetScrollBars(DWORD *pdwScrollBar)
+{
+ *pdwScrollBar = m_dwScrollbar;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetPasswordChar(TCHAR *pch)
+{
+ return S_FALSE;
+}
+
+HRESULT CFormattedTextDraw::TxGetAcceleratorPos(LONG *pcp)
+{
+ *pcp = -1;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetExtent(LPSIZEL lpExtent)
+{
+ return E_NOTIMPL;
+}
+
+HRESULT CFormattedTextDraw::OnTxCharFormatChange(const CHARFORMATW * pcf)
+{
+ memcpy(m_pCF, pcf, pcf->cbSize);
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::OnTxParaFormatChange(const PARAFORMAT * ppf)
+{
+ memcpy(&m_PF, ppf, ppf->cbSize);
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits)
+{
+ *pdwBits = m_dwPropertyBits;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::TxNotify(DWORD iNotify, void *pv)
+{
+ return S_OK;
+}
+
+HIMC CFormattedTextDraw::TxImmGetContext()
+{
+ return NULL;
+}
+
+void CFormattedTextDraw::TxImmReleaseContext(HIMC himc)
+{
+}
+
+HRESULT CFormattedTextDraw::TxGetSelectionBarWidth(LONG *lSelBarWidth)
+{
+ *lSelBarWidth = 100;
+ return S_OK;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// custom functions
+
+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);
+
+ // Get LOGFONT for passed hfont
+ if (!GetObject(hFont, sizeof(LOGFONT), &lf))
+ return E_FAIL;
+
+ // Set CHARFORMAT structure
+ memset(pCF, 0, sizeof(CHARFORMAT2W));
+ pCF->cbSize = sizeof(CHARFORMAT2W);
+
+ hWnd = GetDesktopWindow();
+ hDC = GetDC(hWnd);
+ yPixPerInch = GetDeviceCaps(hDC, LOGPIXELSY);
+ pCF->yHeight = -lf.lfHeight * LY_PER_INCH / yPixPerInch;
+ ReleaseDC(hWnd, hDC);
+
+ pCF->yOffset = 0;
+ pCF->crTextColor = 0;
+
+ pCF->dwEffects = CFM_EFFECTS | CFE_AUTOBACKCOLOR;
+ pCF->dwEffects &= ~(CFE_PROTECTED | CFE_LINK | CFE_AUTOCOLOR);
+
+ if(lf.lfWeight < FW_BOLD)
+ pCF->dwEffects &= ~CFE_BOLD;
+
+ if(!lf.lfItalic)
+ pCF->dwEffects &= ~CFE_ITALIC;
+
+ if(!lf.lfUnderline)
+ pCF->dwEffects &= ~CFE_UNDERLINE;
+
+ if(!lf.lfStrikeOut)
+ pCF->dwEffects &= ~CFE_STRIKEOUT;
+
+ pCF->dwMask = CFM_ALL | CFM_BACKCOLOR | CFM_STYLE;
+ pCF->bCharSet = lf.lfCharSet;
+ pCF->bPitchAndFamily = lf.lfPitchAndFamily;
+
+#ifdef UNICODE
+ lstrcpyW(pCF->szFaceName, lf.lfFaceName);
+#else
+ MultiByteToWideChar(CP_ACP, 0, lf.lfFaceName, LF_FACESIZE, pCF->szFaceName, LF_FACESIZE);
+#endif
+
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::InitDefaultCharFormat()
+{
+ return CharFormatFromHFONT(m_pCF, NULL);
+}
+
+HRESULT CFormattedTextDraw::InitDefaultParaFormat()
+{
+ memset(&m_PF, 0, sizeof(PARAFORMAT2));
+ m_PF.cbSize = sizeof(PARAFORMAT2);
+ m_PF.dwMask = PFM_ALL;
+ m_PF.wAlignment = PFA_LEFT;
+ m_PF.cTabCount = 1;
+ m_PF.rgxTabs[0] = lDefaultTab;
+ return S_OK;
+}
+
+HRESULT CFormattedTextDraw::CreateTextServicesObject()
+{
+ HRESULT hr;
+ IUnknown *spUnk;
+
+ 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);
+ spUnk->Release();
+ }
+ return hr;
+}
+
diff --git a/plugins/mTextControl/src/FormattedTextDraw.h b/plugins/mTextControl/src/FormattedTextDraw.h new file mode 100644 index 0000000000..06a939c160 --- /dev/null +++ b/plugins/mTextControl/src/FormattedTextDraw.h @@ -0,0 +1,193 @@ +// Feel free to use this code in your own applications.
+// The Author does not guarantee anything about this code.
+// Author : Yves Maurer
+// FormattedTextDraw.h : Declaration of the CFormattedTextDraw
+
+#ifndef __FORMATTEDTEXTDRAW_H_
+#define __FORMATTEDTEXTDRAW_H_
+
+// be sure to link this project with riched20.lib
+#ifndef LY_PER_INCH
+#define LY_PER_INCH 1440
+#define HOST_BORDER 0
+#endif
+
+typedef struct tagCOOKIE
+{
+ bool isUnicode;
+ union
+ {
+ char *ansi;
+ WCHAR *unicode;
+ };
+ DWORD dwSize;
+ DWORD dwCount;
+} COOKIE, *PCOOKIE;
+
+extern HRESULT (WINAPI *MyCreateTextServices)(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk);
+
+/////////////////////////////////////////////////////////////////////////////
+// IFormatttedTextDraw
+interface IFormattedTextDraw
+{
+public:
+ virtual ~IFormattedTextDraw() {};
+ virtual HRESULT get_NaturalSize(void *hdcDraw, long *Width, long *pVal) = 0;
+ virtual HRESULT Create() = 0;
+ virtual HRESULT Draw(void *hdcDraw, RECT *prc) = 0;
+ virtual HRESULT putRTFTextA(char *newVal) = 0;
+ virtual HRESULT putRTFTextW(WCHAR *newVal) = 0;
+ virtual HRESULT putTextA(char *newVal) = 0;
+ virtual HRESULT putTextW(WCHAR *newVal) = 0;
+
+ virtual ITextServices *getTextService() = 0;
+ virtual ITextDocument *getTextDocument() = 0;
+ virtual void setParentWnd(HWND hwnd, RECT rect) = 0;
+
+// COM-like functions
+ virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0;
+ virtual ULONG STDMETHODCALLTYPE Release(void) = 0;
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+// CFormattedTextDraw
+class CFormattedTextDraw:
+ public ITextHost,
+ public IFormattedTextDraw
+{
+public:
+ CFormattedTextDraw()
+ {
+ HDC hdcScreen;
+
+ hdcScreen = GetDC(NULL);
+ nPixelsPerInchX = GetDeviceCaps(hdcScreen, LOGPIXELSX);
+ nPixelsPerInchY = GetDeviceCaps(hdcScreen, LOGPIXELSY);
+ ReleaseDC(NULL, hdcScreen);
+
+ SetRectEmpty(&m_rcClient);
+ SetRectEmpty(&m_rcViewInset);
+
+ m_pCF = (CHARFORMAT2W*) malloc(sizeof(CHARFORMAT2W));
+
+ InitDefaultCharFormat();
+ InitDefaultParaFormat();
+ m_spTextServices = NULL;
+ m_spTextDocument = NULL;
+
+ m_dwPropertyBits = TXTBIT_RICHTEXT | TXTBIT_MULTILINE | TXTBIT_WORDWRAP | TXTBIT_USECURRENTBKG;
+ m_dwScrollbar = 0;
+ m_dwMaxLength = INFINITE;
+ }
+
+ ~CFormattedTextDraw()
+ {
+ free(m_pCF);
+ if (m_spTextServices != NULL)
+ m_spTextServices->Release();
+ if (m_spTextDocument != NULL)
+ m_spTextDocument->Release();
+ }
+
+// Minimal COM functionality
+ HRESULT STDMETHODCALLTYPE QueryInterface(
+ /* [in] */ REFIID riid,
+ /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
+ {
+ *ppvObject = NULL;
+ return S_FALSE;
+ }
+
+ ULONG STDMETHODCALLTYPE AddRef(void)
+ {
+ return 0;
+ }
+
+ ULONG STDMETHODCALLTYPE Release(void)
+ {
+ return 0;
+ }
+
+// IFormattedTextDraw
+public:
+ HRESULT get_NaturalSize(void *hdcDraw, long *Width, long *pVal);
+ HRESULT Create();
+ HRESULT Draw(void *hdcDraw, RECT *prc);
+ HRESULT putRTFTextA(char *newVal);
+ HRESULT putRTFTextW(WCHAR *newVal);
+ HRESULT putTextA(char *newVal);
+ HRESULT putTextW(WCHAR *newVal);
+
+ ITextServices *getTextService() { return m_spTextServices; };
+ ITextDocument *getTextDocument() { return m_spTextDocument; };
+ virtual void setParentWnd(HWND hwnd, RECT rect) { m_hwndParent = hwnd; m_rcClient = rect; }
+
+// ITextHost
+ HDC TxGetDC();
+ INT TxReleaseDC(HDC hdc);
+ BOOL TxShowScrollBar(INT fnBar, BOOL fShow);
+ BOOL TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags);
+ BOOL TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw);
+ BOOL TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw);
+ void TxInvalidateRect(LPCRECT prc, BOOL fMode);
+ void TxViewChange(BOOL fUpdate);
+ BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight);
+ BOOL TxShowCaret(BOOL fShow);
+ BOOL TxSetCaretPos(INT x, INT y);
+ BOOL TxSetTimer(UINT idTimer, UINT uTimeout);
+ void TxKillTimer(UINT idTimer);
+ void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll);
+ void TxSetCapture(BOOL fCapture);
+ void TxSetFocus();
+ void TxSetCursor(HCURSOR hcur, BOOL fText);
+ BOOL TxScreenToClient(LPPOINT lppt);
+ BOOL TxClientToScreen(LPPOINT lppt);
+ HRESULT TxActivate(LONG * plOldState);
+ HRESULT TxDeactivate(LONG lNewState);
+ HRESULT TxGetClientRect(LPRECT prc);
+ HRESULT TxGetViewInset(LPRECT prc);
+ HRESULT TxGetCharFormat(const CHARFORMATW **ppCF);
+ HRESULT TxGetParaFormat(const PARAFORMAT **ppPF);
+ COLORREF TxGetSysColor(int nIndex);
+ HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle);
+ HRESULT TxGetMaxLength(DWORD *plength);
+ HRESULT TxGetScrollBars(DWORD *pdwScrollBar);
+ HRESULT TxGetPasswordChar(TCHAR *pch);
+ HRESULT TxGetAcceleratorPos(LONG *pcp);
+ HRESULT TxGetExtent(LPSIZEL lpExtent);
+ HRESULT OnTxCharFormatChange(const CHARFORMATW * pcf);
+ HRESULT OnTxParaFormatChange(const PARAFORMAT * ppf);
+ HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits);
+ HRESULT TxNotify(DWORD iNotify, void *pv);
+ HIMC TxImmGetContext();
+ void TxImmReleaseContext(HIMC himc);
+ HRESULT TxGetSelectionBarWidth(LONG *lSelBarWidth);
+
+// Custom functions
+ HRESULT CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont);
+ HRESULT InitDefaultCharFormat();
+ HRESULT InitDefaultParaFormat();
+ HRESULT CreateTextServicesObject();
+
+// Variables
+ HWND m_hwndParent;
+ RECT m_rcClient; // Client Rect
+ RECT m_rcViewInset; // view rect inset
+ SIZEL m_sizelExtent; // Extent array
+
+ int nPixelsPerInchX; // Pixels per logical inch along width
+ int nPixelsPerInchY; // Pixels per logical inch along height
+
+ CHARFORMAT2W *m_pCF;
+ PARAFORMAT2 m_PF;
+ DWORD m_dwScrollbar; // Scroll bar style
+ DWORD m_dwPropertyBits; // Property bits
+ DWORD m_dwMaxLength;
+ COOKIE m_editCookie;
+
+ ITextServices *m_spTextServices;
+ ITextDocument *m_spTextDocument;
+};
+
+#endif //__FORMATTEDTEXTDRAW_H_
diff --git a/plugins/mTextControl/src/ImageDataObjectHlp.cpp b/plugins/mTextControl/src/ImageDataObjectHlp.cpp new file mode 100644 index 0000000000..fd81142271 --- /dev/null +++ b/plugins/mTextControl/src/ImageDataObjectHlp.cpp @@ -0,0 +1,252 @@ +/*
+Miranda SmileyAdd Plugin
+Copyright (C) 2004-2005 Rein-Peter de Boer (peacow) and followers
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+//imagedataobject
+//code taken partly from public example on the internet, source unknown.
+
+#include "headers.h"
+
+struct EMFCACHE
+{
+ HENHMETAFILE hEmf;
+ HICON hIcon;
+ EMFCACHE *prev;
+ EMFCACHE *next;
+} *emfCache = 0;
+int emfCacheSize = 0;
+CRITICAL_SECTION csEmfCache;
+
+void LoadEmfCache()
+{
+ InitializeCriticalSection(&csEmfCache);
+}
+
+void UnloadEmfCache()
+{
+ while (emfCache)
+ {
+ EMFCACHE *tmp = emfCache->next;
+ delete emfCache;
+ emfCache = tmp;
+ }
+ DeleteCriticalSection(&csEmfCache);
+}
+
+HENHMETAFILE CacheIconToEmf(HICON hIcon)
+{
+ HENHMETAFILE result = 0;
+ EnterCriticalSection(&csEmfCache);
+ for (EMFCACHE *p = emfCache; p; p = p->next)
+ if (p->hIcon == hIcon)
+ {
+ if (p->prev)
+ {
+ p->prev->next = p->next;
+ if (p->next) p->next->prev = p->prev;
+ p->prev = 0;
+ emfCache->prev = p;
+ p->next = emfCache;
+ emfCache = p;
+ result = CopyEnhMetaFile(emfCache->hEmf, 0);
+ break;
+ }
+ }
+
+ // cache new item
+ if (!result)
+ {
+ EMFCACHE *newItem = new EMFCACHE;
+ newItem->prev = 0;
+ newItem->next = emfCache;
+ if (emfCache) emfCache->prev = newItem;
+ emfCache = newItem;
+ emfCacheSize++;
+
+ HDC emfdc = CreateEnhMetaFile(NULL, NULL, NULL, _T("icon"));
+ DrawIconEx(emfdc, 0, 0, (HICON)hIcon, 16, 16, 0, NULL, DI_NORMAL);
+ emfCache->hIcon = hIcon;
+ emfCache->hEmf = CloseEnhMetaFile(emfdc);
+ result = CopyEnhMetaFile(emfCache->hEmf, 0);
+ }
+
+ // tail cutoff
+ if (emfCacheSize > 20)
+ {
+ int n = 0;
+ EMFCACHE *p;
+ for (p = emfCache; p; p = p->next)
+ if (++n > 20)
+ break;
+ while (p->next)
+ {
+ EMFCACHE *tmp = p->next;
+ p->next = p->next->next;
+ delete tmp;
+ }
+ if (p->next) p->next->prev = p;
+ emfCacheSize = 20;
+ }
+
+ LeaveCriticalSection(&csEmfCache);
+
+ return result;
+}
+
+HRESULT CreateDataObject(const FORMATETC *fmtetc, const STGMEDIUM *stgmed, UINT count, IDataObject **ppDataObject);
+
+// returns true on success, false on failure
+//bool InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap, HGLOBAL hGlobal)
+bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf)
+{
+ SCODE sc;
+
+ // Get the image data object
+ //
+ static const FORMATETC lc_format[] =
+ {
+ { CF_ENHMETAFILE, 0, DVASPECT_CONTENT, -1, TYMED_ENHMF }//,
+// { CF_BITMAP, 0, DVASPECT_CONTENT, -1, TYMED_GDI },
+// { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }
+ };
+
+ STGMEDIUM lc_stgmed[] =
+ {
+ { TYMED_ENHMF, { (HBITMAP)hEmf }, 0 }//,
+// { TYMED_GDI, { hBitmap }, 0 },
+// { TYMED_HGLOBAL, { (HBITMAP)hGlobal }, 0 }
+ };
+
+ IDataObject *pods;
+ CreateDataObject(lc_format, lc_stgmed, 1, &pods);
+
+ // Get the RichEdit container site
+ //
+ IOleClientSite *pOleClientSite;
+ pRichEditOle->GetClientSite(&pOleClientSite);
+
+ // Initialize a Storage Object
+ //
+ LPLOCKBYTES lpLockBytes = NULL;
+ sc = CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
+ if (sc != S_OK)
+ {
+ pOleClientSite->Release();
+ return false;
+ }
+
+ IStorage *pStorage;
+ sc = StgCreateDocfileOnILockBytes(lpLockBytes,
+ STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage);
+ if (sc != S_OK)
+ {
+ lpLockBytes->Release();
+ pOleClientSite->Release();
+ return false;
+ }
+
+ // The final ole object which will be inserted in the richedit control
+ //
+ IOleObject *pOleObject;
+ sc = OleCreateStaticFromData(pods, IID_IOleObject, OLERENDER_FORMAT,
+ (LPFORMATETC)lc_format, pOleClientSite, pStorage, (void **)&pOleObject);
+ if (sc != S_OK)
+ {
+ pStorage->Release();
+ lpLockBytes->Release();
+ pOleClientSite->Release();
+ return false;
+ }
+
+ // all items are "contained" -- this makes our reference to this object
+ // weak -- which is needed for links to embedding silent update.
+ OleSetContainedObject(pOleObject, TRUE);
+
+ // Now Add the object to the RichEdit
+ //
+ REOBJECT reobject = { 0 };
+
+ reobject.cbStruct = sizeof(REOBJECT);
+ reobject.cp = REO_CP_SELECTION ;
+ reobject.dvaspect = DVASPECT_CONTENT;
+ reobject.poleobj = pOleObject;
+ reobject.polesite = pOleClientSite;
+ reobject.pstg = pStorage;
+ reobject.dwFlags = REO_BELOWBASELINE;
+
+ sc = pOleObject->GetUserClassID(&reobject.clsid);
+ if (sc != S_OK)
+ {
+ pOleObject->Release();
+ pStorage->Release();
+ lpLockBytes->Release();
+ pOleClientSite->Release();
+ return false;
+ }
+
+ // Insert the bitmap at the current location in the richedit control
+ //
+ sc = pRichEditOle->InsertObject(&reobject);
+
+ // Release all unnecessary interfaces
+ //
+ pOleObject->Release();
+ pStorage->Release();
+ lpLockBytes->Release();
+ pOleClientSite->Release();
+ pods->Release();
+
+ return sc == S_OK;
+}
+/*
+int RichEditVersion(void)
+{
+ // get size of version information
+ DWORD dummy;
+ DWORD size = ::GetFileVersionInfoSize(_T("riched20.dll"), &dummy);
+ if (!size) return -1; // unexpected failure
+
+ // allocate a buffer for version information
+ BYTE* buffer = (BYTE*) new BYTE[size];
+
+ // get the version information
+ if (!::GetFileVersionInfo(_T("riched20.dll"), 0, size, buffer))
+ {
+ delete[] buffer;
+ return -1; // unexpected faiure
+ }
+
+ // get the static version information
+ VS_FIXEDFILEINFO* vsInfo;
+ UINT vsInfoSize;
+ if (!::VerQueryValue(buffer, _T("\\"), (LPVOID*) &vsInfo, &vsInfoSize))
+ {
+ delete[] buffer;
+ return -1; // unexpected failure
+ }
+
+ int FileVersionMinor = LOWORD(vsInfo->dwFileVersionMS);
+
+ // free the buffer
+ delete[] buffer;
+
+ return FileVersionMinor ? 3 : 2;
+}
+
+bool g_HiddenTextSupported = RichEditVersion() == 3;
+*/
\ No newline at end of file diff --git a/plugins/mTextControl/src/ImageDataObjectHlp.h b/plugins/mTextControl/src/ImageDataObjectHlp.h new file mode 100644 index 0000000000..8b8e030f6f --- /dev/null +++ b/plugins/mTextControl/src/ImageDataObjectHlp.h @@ -0,0 +1,32 @@ +/*
+Miranda SmileyAdd Plugin
+Copyright (C) 2004 Rein-Peter de Boer (peacow)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef _IMAGEDATAOBJECTHLP_
+#define _IMAGEDATAOBJECTHLP_
+
+#include <richole.h>
+
+void LoadEmfCache();
+void UnloadEmfCache();
+HENHMETAFILE CacheIconToEmf(HICON hIcon);
+
+//bool InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap, HGLOBAL hGlobal);
+bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf);
+
+#endif
diff --git a/plugins/mTextControl/src/dataobject.cpp b/plugins/mTextControl/src/dataobject.cpp new file mode 100644 index 0000000000..44165fe279 --- /dev/null +++ b/plugins/mTextControl/src/dataobject.cpp @@ -0,0 +1,290 @@ +//
+// DATAOBJECT.CPP
+//
+// Implementation of the IDataObject COM interface
+//
+// By J Brown 2004
+//
+// www.catch22.net
+//
+
+//#define STRICT
+
+#include "headers.h"
+
+const ULONG MAX_FORMATS = 100;
+
+HRESULT CreateEnumFormatEtc(UINT nNumFormats, FORMATETC *pFormatEtc, IEnumFORMATETC **ppEnumFormatEtc);
+
+class CDataObject : public IDataObject
+{
+public:
+ //
+ // IUnknown members
+ //
+ HRESULT __stdcall QueryInterface (REFIID iid, void ** ppvObject);
+ ULONG __stdcall AddRef (void);
+ ULONG __stdcall Release (void);
+
+ //
+ // IDataObject members
+ //
+ HRESULT __stdcall GetData (FORMATETC *pFormatEtc, STGMEDIUM *pMedium);
+ HRESULT __stdcall GetDataHere (FORMATETC *pFormatEtc, STGMEDIUM *pMedium);
+ HRESULT __stdcall QueryGetData (FORMATETC *pFormatEtc);
+ HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC *pFormatEct, FORMATETC *pFormatEtcOut);
+ HRESULT __stdcall SetData (FORMATETC *pFormatEtc, STGMEDIUM *pMedium, BOOL fRelease);
+ HRESULT __stdcall EnumFormatEtc (DWORD dwDirection, IEnumFORMATETC **ppEnumFormatEtc);
+ HRESULT __stdcall DAdvise (FORMATETC *pFormatEtc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection);
+ HRESULT __stdcall DUnadvise (DWORD dwConnection);
+ HRESULT __stdcall EnumDAdvise (IEnumSTATDATA **ppEnumAdvise);
+
+ //
+ // Constructor / Destructor
+ //
+ CDataObject(const FORMATETC *fmt, const STGMEDIUM *stgmed, int count);
+ ~CDataObject();
+
+private:
+
+ int LookupFormatEtc(FORMATETC *pFormatEtc);
+
+ //
+ // any private members and functions
+ //
+ LONG m_lRefCount;
+
+ FORMATETC *m_pFormatEtc;
+ STGMEDIUM *m_pStgMedium;
+ LONG m_nNumFormats;
+
+};
+
+//
+// Constructor
+//
+CDataObject::CDataObject(const FORMATETC *fmtetc, const STGMEDIUM *stgmed, int count)
+{
+ m_lRefCount = 1;
+ m_nNumFormats = count;
+
+ m_pFormatEtc = new FORMATETC[count];
+ m_pStgMedium = new STGMEDIUM[count];
+
+ for(int i = 0; i < count; i++)
+ {
+ m_pFormatEtc[i] = fmtetc[i];
+ m_pStgMedium[i] = stgmed[i];
+ }
+}
+
+//
+// Destructor
+//
+CDataObject::~CDataObject()
+{
+ // cleanup
+ for (int i = 0; i < m_nNumFormats; i++)
+ {
+// ReleaseStgMedium(&m_pStgMedium[i]);
+ }
+
+ if(m_pFormatEtc) delete[] m_pFormatEtc;
+ if(m_pStgMedium) delete[] m_pStgMedium;
+}
+
+//
+// IUnknown::AddRef
+//
+ULONG __stdcall CDataObject::AddRef(void)
+{
+ // increment object reference count
+ return InterlockedIncrement(&m_lRefCount);
+}
+
+//
+// IUnknown::Release
+//
+ULONG __stdcall CDataObject::Release(void)
+{
+ // decrement object reference count
+ LONG count = InterlockedDecrement(&m_lRefCount);
+
+ if(count == 0)
+ {
+ delete this;
+ return 0;
+ }
+ else
+ {
+ return count;
+ }
+}
+
+//
+// IUnknown::QueryInterface
+//
+HRESULT __stdcall CDataObject::QueryInterface(REFIID iid, void **ppvObject)
+{
+ // check to see what interface has been requested
+ if(iid == IID_IDataObject || iid == IID_IUnknown)
+ {
+ AddRef();
+ *ppvObject = this;
+ return S_OK;
+ }
+ else
+ {
+ *ppvObject = 0;
+ return E_NOINTERFACE;
+ }
+}
+
+int CDataObject::LookupFormatEtc(FORMATETC *pFormatEtc)
+{
+ for (int i = 0; i < m_nNumFormats; i++)
+ {
+ if((pFormatEtc->tymed & m_pFormatEtc[i].tymed) &&
+ pFormatEtc->cfFormat == m_pFormatEtc[i].cfFormat &&
+ pFormatEtc->dwAspect == m_pFormatEtc[i].dwAspect)
+ {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+//
+// IDataObject::GetData
+//
+HRESULT __stdcall CDataObject::GetData (FORMATETC *pFormatEtc, STGMEDIUM *pMedium)
+{
+ int idx;
+
+ //
+ // try to match the requested FORMATETC with one of our supported formats
+ //
+ if((idx = LookupFormatEtc(pFormatEtc)) == -1)
+ {
+ return DV_E_FORMATETC;
+ }
+
+ //
+ // found a match! transfer the data into the supplied storage-medium
+ //
+ pMedium->tymed = m_pFormatEtc[idx].tymed;
+ pMedium->pUnkForRelease = 0;
+
+ switch (pMedium->tymed)
+ {
+ case TYMED_HGLOBAL:
+ case TYMED_GDI:
+ case TYMED_ENHMF:
+// pMedium->hBitmap = (HBITMAP)OleDuplicateData(m_pStgMedium[idx].hBitmap, pFormatEtc->cfFormat, 0);
+ pMedium->hBitmap = m_pStgMedium[idx].hBitmap;
+ break;
+
+ default:
+ return DV_E_FORMATETC;
+ }
+ if (pMedium->hBitmap == NULL) return STG_E_MEDIUMFULL;
+
+ return S_OK;
+}
+
+//
+// IDataObject::GetDataHere
+//
+HRESULT __stdcall CDataObject::GetDataHere (FORMATETC *pFormatEtc, STGMEDIUM *pMedium)
+{
+ // GetDataHere is only required for IStream and IStorage mediums
+ // It is an error to call GetDataHere for things like HGLOBAL and other clipboard formats
+ //
+ // OleFlushClipboard
+ //
+ return DATA_E_FORMATETC;
+}
+
+//
+// IDataObject::QueryGetData
+//
+// Called to see if the IDataObject supports the specified format of data
+//
+HRESULT __stdcall CDataObject::QueryGetData (FORMATETC *pFormatEtc)
+{
+ return (LookupFormatEtc(pFormatEtc) == -1) ? DV_E_FORMATETC : S_OK;
+}
+
+//
+// IDataObject::GetCanonicalFormatEtc
+//
+HRESULT __stdcall CDataObject::GetCanonicalFormatEtc (FORMATETC *pFormatEct, FORMATETC *pFormatEtcOut)
+{
+ // Apparently we have to set this field to NULL even though we don't do anything else
+ pFormatEtcOut->ptd = NULL;
+ return E_NOTIMPL;
+}
+
+//
+// IDataObject::SetData
+//
+HRESULT __stdcall CDataObject::SetData (FORMATETC *pFormatEtc, STGMEDIUM *pMedium, BOOL fRelease)
+{
+ return E_NOTIMPL;
+}
+
+//
+// IDataObject::EnumFormatEtc
+//
+HRESULT __stdcall CDataObject::EnumFormatEtc (DWORD dwDirection, IEnumFORMATETC **ppEnumFormatEtc)
+{
+ if(dwDirection == DATADIR_GET)
+ {
+ // for Win2k+ you can use the SHCreateStdEnumFmtEtc API call, however
+ // to support all Windows platforms we need to implement IEnumFormatEtc ourselves.
+ return CreateEnumFormatEtc(m_nNumFormats, m_pFormatEtc, ppEnumFormatEtc);
+ }
+ else
+ {
+ // the direction specified is not support for drag+drop
+ return E_NOTIMPL;
+ }
+}
+
+//
+// IDataObject::DAdvise
+//
+HRESULT __stdcall CDataObject::DAdvise (FORMATETC *pFormatEtc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
+{
+ return OLE_E_ADVISENOTSUPPORTED;
+}
+
+//
+// IDataObject::DUnadvise
+//
+HRESULT __stdcall CDataObject::DUnadvise (DWORD dwConnection)
+{
+ return OLE_E_ADVISENOTSUPPORTED;
+}
+
+//
+// IDataObject::EnumDAdvise
+//
+HRESULT __stdcall CDataObject::EnumDAdvise (IEnumSTATDATA **ppEnumAdvise)
+{
+ return OLE_E_ADVISENOTSUPPORTED;
+}
+
+//
+// Helper function
+//
+HRESULT CreateDataObject (const FORMATETC *fmtetc, const STGMEDIUM *stgmeds, UINT count, IDataObject **ppDataObject)
+{
+ if(ppDataObject == 0)
+ return E_INVALIDARG;
+
+ *ppDataObject = new CDataObject(fmtetc, stgmeds, count);
+
+ return (*ppDataObject) ? S_OK : E_OUTOFMEMORY;
+}
diff --git a/plugins/mTextControl/src/enumformat.cpp b/plugins/mTextControl/src/enumformat.cpp new file mode 100644 index 0000000000..7daac154d7 --- /dev/null +++ b/plugins/mTextControl/src/enumformat.cpp @@ -0,0 +1,232 @@ +//
+// ENUMFORMAT.CPP
+//
+// By J Brown 2004
+//
+// www.catch22.net
+//
+// Implementation of the IEnumFORMATETC interface
+//
+// For Win2K and above look at the SHCreateStdEnumFmtEtc API call!!
+//
+// Apparently the order of formats in an IEnumFORMATETC object must be
+// the same as those that were stored in the clipboard
+//
+//
+
+//#define STRICT
+
+#include "headers.h"
+
+class CEnumFormatEtc : public IEnumFORMATETC
+{
+public:
+
+ //
+ // IUnknown members
+ //
+ HRESULT __stdcall QueryInterface (REFIID iid, void ** ppvObject);
+ ULONG __stdcall AddRef (void);
+ ULONG __stdcall Release (void);
+
+ //
+ // IEnumFormatEtc members
+ //
+ HRESULT __stdcall Next (ULONG celt, FORMATETC * rgelt, ULONG * pceltFetched);
+ HRESULT __stdcall Skip (ULONG celt);
+ HRESULT __stdcall Reset (void);
+ HRESULT __stdcall Clone (IEnumFORMATETC ** ppEnumFormatEtc);
+
+ //
+ // Construction / Destruction
+ //
+ CEnumFormatEtc(FORMATETC *pFormatEtc, int nNumFormats);
+ ~CEnumFormatEtc();
+
+private:
+
+ LONG m_lRefCount; // Reference count for this COM interface
+ ULONG m_nIndex; // current enumerator index
+ ULONG m_nNumFormats; // number of FORMATETC members
+ FORMATETC * m_pFormatEtc; // array of FORMATETC objects
+};
+
+//
+// "Drop-in" replacement for SHCreateStdEnumFmtEtc. Called by CDataObject::EnumFormatEtc
+//
+HRESULT CreateEnumFormatEtc(UINT nNumFormats, FORMATETC *pFormatEtc, IEnumFORMATETC **ppEnumFormatEtc)
+{
+ if(nNumFormats == 0 || pFormatEtc == 0 || ppEnumFormatEtc == 0)
+ return E_INVALIDARG;
+
+ *ppEnumFormatEtc = new CEnumFormatEtc(pFormatEtc, nNumFormats);
+
+ return (*ppEnumFormatEtc) ? S_OK : E_OUTOFMEMORY;
+}
+
+//
+// Helper function to perform a "deep" copy of a FORMATETC
+//
+static void DeepCopyFormatEtc(FORMATETC *dest, FORMATETC *source)
+{
+ // copy the source FORMATETC into dest
+ *dest = *source;
+
+ if(source->ptd)
+ {
+ // allocate memory for the DVTARGETDEVICE if necessary
+ dest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
+
+ // copy the contents of the source DVTARGETDEVICE into dest->ptd
+ *(dest->ptd) = *(source->ptd);
+ }
+}
+
+//
+// Constructor
+//
+CEnumFormatEtc::CEnumFormatEtc(FORMATETC *pFormatEtc, int nNumFormats)
+{
+ m_lRefCount = 1;
+ m_nIndex = 0;
+ m_nNumFormats = nNumFormats;
+ m_pFormatEtc = new FORMATETC[nNumFormats];
+
+ // copy the FORMATETC structures
+ for(int i = 0; i < nNumFormats; i++)
+ {
+ DeepCopyFormatEtc(&m_pFormatEtc[i], &pFormatEtc[i]);
+ }
+}
+
+//
+// Destructor
+//
+CEnumFormatEtc::~CEnumFormatEtc()
+{
+ if(m_pFormatEtc)
+ {
+ for(ULONG i = 0; i < m_nNumFormats; i++)
+ {
+ if(m_pFormatEtc[i].ptd)
+ CoTaskMemFree(m_pFormatEtc[i].ptd);
+ }
+
+ delete[] m_pFormatEtc;
+ }
+}
+
+//
+// IUnknown::AddRef
+//
+ULONG __stdcall CEnumFormatEtc::AddRef(void)
+{
+ // increment object reference count
+ return InterlockedIncrement(&m_lRefCount);
+}
+
+//
+// IUnknown::Release
+//
+ULONG __stdcall CEnumFormatEtc::Release(void)
+{
+ // decrement object reference count
+ LONG count = InterlockedDecrement(&m_lRefCount);
+
+ if(count == 0)
+ {
+ delete this;
+ return 0;
+ }
+ else
+ {
+ return count;
+ }
+}
+
+//
+// IUnknown::QueryInterface
+//
+HRESULT __stdcall CEnumFormatEtc::QueryInterface(REFIID iid, void **ppvObject)
+{
+ // check to see what interface has been requested
+ if(iid == IID_IEnumFORMATETC || iid == IID_IUnknown)
+ {
+ AddRef();
+ *ppvObject = this;
+ return S_OK;
+ }
+ else
+ {
+ *ppvObject = 0;
+ return E_NOINTERFACE;
+ }
+}
+
+//
+// IEnumFORMATETC::Next
+//
+// If the returned FORMATETC structure contains a non-null "ptd" member, then
+// the caller must free this using CoTaskMemFree (stated in the COM documentation)
+//
+HRESULT __stdcall CEnumFormatEtc::Next(ULONG celt, FORMATETC *pFormatEtc, ULONG * pceltFetched)
+{
+ ULONG copied = 0;
+
+ // validate arguments
+ if(celt == 0 || pFormatEtc == 0)
+ return E_INVALIDARG;
+
+ // copy FORMATETC structures into caller's buffer
+ while(m_nIndex < m_nNumFormats && copied < celt)
+ {
+ DeepCopyFormatEtc(&pFormatEtc[copied], &m_pFormatEtc[m_nIndex]);
+ copied++;
+ m_nIndex++;
+ }
+
+ // store result
+ if(pceltFetched != 0)
+ *pceltFetched = copied;
+
+ // did we copy all that was requested?
+ return (copied == celt) ? S_OK : S_FALSE;
+}
+
+//
+// IEnumFORMATETC::Skip
+//
+HRESULT __stdcall CEnumFormatEtc::Skip(ULONG celt)
+{
+ m_nIndex += celt;
+ return (m_nIndex <= m_nNumFormats) ? S_OK : S_FALSE;
+}
+
+//
+// IEnumFORMATETC::Reset
+//
+HRESULT __stdcall CEnumFormatEtc::Reset(void)
+{
+ m_nIndex = 0;
+ return S_OK;
+}
+
+//
+// IEnumFORMATETC::Clone
+//
+HRESULT __stdcall CEnumFormatEtc::Clone(IEnumFORMATETC ** ppEnumFormatEtc)
+{
+ HRESULT hResult;
+
+ // make a duplicate enumerator
+ hResult = CreateEnumFormatEtc(m_nNumFormats, m_pFormatEtc, ppEnumFormatEtc);
+
+ if(hResult == S_OK)
+ {
+ // manually set the index state
+ ((CEnumFormatEtc *) *ppEnumFormatEtc)->m_nIndex = m_nIndex;
+ }
+
+ return hResult;
+}
+
diff --git a/plugins/mTextControl/src/fancy_rtf.cpp b/plugins/mTextControl/src/fancy_rtf.cpp new file mode 100644 index 0000000000..01ad6bc0f3 --- /dev/null +++ b/plugins/mTextControl/src/fancy_rtf.cpp @@ -0,0 +1,179 @@ +#include "headers.h"
+
+struct BBCodeInfo
+{
+ TCHAR *start;
+ TCHAR *end;
+ bool (* func)(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD cookie);
+ DWORD cookie;
+};
+
+enum { BBS_BOLD_S, BBS_BOLD_E, BBS_ITALIC_S, BBS_ITALIC_E, BBS_UNDERLINE_S, BBS_UNDERLINE_E,
+ BBS_STRIKEOUT_S, BBS_STRIKEOUT_E, BBS_COLOR_S, BBS_COLOR_E, BBS_URL1, BBS_URL2,
+ BBS_IMG1, BBS_IMG2 };
+
+static bool bbCodeSimpleFunc(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD cookie)
+{
+ CHARFORMAT cf = {0};
+ cf.cbSize = sizeof(cf);
+ switch (cookie)
+ {
+ case BBS_BOLD_S:
+ cf.dwMask = CFM_BOLD;
+ cf.dwEffects = CFE_BOLD;
+ break;
+ case BBS_BOLD_E:
+ cf.dwMask = CFM_BOLD;
+ break;
+ case BBS_ITALIC_S:
+ cf.dwMask = CFM_ITALIC;
+ cf.dwEffects = CFE_ITALIC;
+ break;
+ case BBS_ITALIC_E:
+ cf.dwMask = CFM_ITALIC;
+ break;
+ case BBS_UNDERLINE_S:
+ cf.dwMask = CFM_UNDERLINE;
+ cf.dwEffects = CFE_UNDERLINE;
+ break;
+ case BBS_UNDERLINE_E:
+ cf.dwMask = CFM_UNDERLINE;
+ break;
+ case BBS_STRIKEOUT_S:
+ cf.dwMask = CFM_STRIKEOUT;
+ cf.dwEffects = CFE_STRIKEOUT;
+ break;
+ case BBS_STRIKEOUT_E:
+ cf.dwMask = CFM_STRIKEOUT;
+ break;
+ }
+
+ ITextServices *ts = ftd->getTextService();
+
+ LRESULT lResult;
+ ts->TxSendMessage(EM_SETSEL, range.cpMin, -1, &lResult);
+ ts->TxSendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf, &lResult);
+ ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult);
+ ts->TxSendMessage(EM_REPLACESEL, FALSE, (LPARAM)_T(""), &lResult);
+
+ return true;
+}
+
+static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD cookie)
+{
+ ITextServices *ts = ftd->getTextService();
+ ITextDocument *td = ftd->getTextDocument();
+
+ long cnt;
+ LRESULT lResult;
+/*
+ TEXTRANGE trg;
+ trg.chrg = range;
+ trg.lpstrText = new TCHAR[trg.chrg.cpMax - trg.chrg.cpMin + 1];
+ ts->TxSendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&trg, &lResult);
+ MessageBox(0, txt, trg.lpstrText, MB_OK);
+*/
+ ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult);
+ IRichEditOle* RichEditOle;
+ ts->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle, &lResult);
+ td->Freeze(&cnt);
+// HDC emfdc = CreateEnhMetaFile(NULL, NULL, NULL, _T("icon"));
+// DrawIconEx(emfdc, 0, 0, (HICON)_ttol(txt), 16, 16, 0, NULL, DI_NORMAL);
+// InsertBitmap(RichEditOle, CloseEnhMetaFile(emfdc));
+#ifdef _WIN64
+ bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_tstoi64(txt)));
+#else
+ bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_ttoi(txt)));
+#endif
+
+ td->Unfreeze(&cnt);
+ RichEditOle->Release();
+ return res;
+}
+
+static BBCodeInfo bbCodes[] =
+{
+ { _T("[b]"), 0, bbCodeSimpleFunc, BBS_BOLD_S },
+ { _T("[/b]"), 0, bbCodeSimpleFunc, BBS_BOLD_E },
+ { _T("[i]"), 0, bbCodeSimpleFunc, BBS_ITALIC_S },
+ { _T("[/i]"), 0, bbCodeSimpleFunc, BBS_ITALIC_E },
+ { _T("[u]"), 0, bbCodeSimpleFunc, BBS_UNDERLINE_S },
+ { _T("[/u]"), 0, bbCodeSimpleFunc, BBS_UNDERLINE_E },
+ { _T("[s]"), 0, bbCodeSimpleFunc, BBS_STRIKEOUT_S },
+ { _T("[/s]"), 0, bbCodeSimpleFunc, BBS_STRIKEOUT_E },
+
+// { _T("[color="), _T("]"), bbCodeSimpleFunc, BBS_COLOR_S },
+// { _T("[/color]"), 0, bbCodeSimpleFunc, BBS_COLOR_E }
+
+ { _T("[$hicon="), _T("$]"), bbCodeImageFunc, 0 }
+
+// { _T("[url]"), _T("[/url]"), bbCodeSimpleFunc, BBS_URL1 },
+// { _T("[url="), _T("]"), bbCodeSimpleFunc, BBS_URL2 },
+// { _T("[url]"), _T("[/url]"), bbCodeSimpleFunc, BBS_IMG1 },
+// { _T("[url="), _T("]"), bbCodeSimpleFunc, BBS_IMG2 },
+};
+static int bbCodeCount = sizeof(bbCodes) / sizeof(*bbCodes);
+
+void bbCodeParse(IFormattedTextDraw *ftd)
+{
+ ITextServices *ts = ftd->getTextService();
+ LRESULT lResult;
+
+ int pos = 0;
+ for (bool found = true; found; )
+ {
+ found = false;
+ CHARRANGE fRange; fRange.cpMin = -1;
+ TCHAR *fText = 0;
+ BBCodeInfo *fBBCode;
+
+ for (int i = 0; i < bbCodeCount; i++)
+ {
+ CHARRANGE range;
+
+ FINDTEXTEX fte;
+ fte.chrg.cpMin = pos;
+ fte.chrg.cpMax = -1;
+
+ fte.lpstrText = bbCodes[i].start;
+ ts->TxSendMessage(EM_FINDTEXTEX, (WPARAM)FR_DOWN, (LPARAM)&fte, &lResult);
+ if (lResult == -1)
+ continue;
+ range = fte.chrgText;
+
+ if (bbCodes[i].end)
+ {
+ fte.chrg.cpMin = fte.chrgText.cpMax;
+ fte.lpstrText = bbCodes[i].end;
+ ts->TxSendMessage(EM_FINDTEXTEX, (WPARAM)FR_DOWN, (LPARAM)&fte, &lResult);
+ if (lResult == -1)
+ continue;
+ range.cpMax = fte.chrgText.cpMax;
+ }
+
+ if ((fRange.cpMin == -1) || (fRange.cpMin > range.cpMin))
+ {
+ fRange = range;
+ fBBCode = bbCodes+i;
+ found = true;
+
+ if (fText) delete [] fText;
+ if (bbCodes[i].end)
+ {
+ TEXTRANGE trg;
+ trg.chrg.cpMin = fte.chrg.cpMin;
+ trg.chrg.cpMax = fte.chrgText.cpMin;
+ trg.lpstrText = new TCHAR[trg.chrg.cpMax - trg.chrg.cpMin + 1];
+ ts->TxSendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&trg, &lResult);
+ fText = trg.lpstrText;
+ }
+ }
+ }
+
+ if (found)
+ {
+ found = fBBCode->func(ftd, fRange, fText, fBBCode->cookie);
+ if (fText) delete [] fText;
+ }
+ }
+}
diff --git a/plugins/mTextControl/src/fancy_rtf.h b/plugins/mTextControl/src/fancy_rtf.h new file mode 100644 index 0000000000..ed1fcb1d2c --- /dev/null +++ b/plugins/mTextControl/src/fancy_rtf.h @@ -0,0 +1,6 @@ +#ifndef __fancy_rtf_h__
+#define __fancy_rtf_h__
+
+void bbCodeParse(IFormattedTextDraw *ts);
+
+#endif // __fancy_rtf_h__
diff --git a/plugins/mTextControl/src/headers.h b/plugins/mTextControl/src/headers.h new file mode 100644 index 0000000000..cc2f4579b9 --- /dev/null +++ b/plugins/mTextControl/src/headers.h @@ -0,0 +1,125 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __headers_h__
+#define __headers_h__
+
+#if defined(UNICODE) && !defined(_UNICODE)
+ #define _UNICODE
+#elif defined(_UNICODE) && !defined(UNICODE)
+ #define UNICODE
+#endif
+
+#ifndef UNICODE
+ #define OLE2ANSI
+#elif defined(OLE2ANSI)
+ #undef OLE2ANSI
+#endif
+
+#define _CRT_SECURE_NO_DEPRECATE
+
+//Windows headers
+#define _WIN32_WINNT 0x0500
+#define WINVER 0x0500
+#define OEMRESOURCE
+#include <tchar.h>
+#include <windows.h>
+#include <richedit.h>
+#include <richole.h>
+#include <tom.h>
+#include <textserv.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <stdio.h>
+
+//Resources
+//#include "../res/resource.h"
+
+#ifdef _cplusplus
+extern "C" {
+#endif
+ //Miranda headers
+ #include <newpluginapi.h>
+ #include <win2k.h>
+ #include <m_system.h>
+ #include <m_plugins.h>
+ #include <m_clui.h>
+ #include <m_clist.h>
+ #include <m_options.h>
+ #include <m_skin.h>
+ #include <m_langpack.h>
+ #include <m_database.h>
+ #include <m_protocols.h>
+ #include <m_utils.h>
+// #include <m_icolib.h>
+
+// The following ifdef block is the standard way of creating macros which make exporting
+// from a DLL simpler. All files within this DLL are compiled with the MTEXTCONTROL_EXPORTS
+// symbol defined on the command line. this symbol should not be defined on any project
+// that uses this DLL. This way any other project whose source files include this file see
+// DLL_API functions as being imported from a DLL, wheras this DLL sees symbols
+// defined with this macro as being exported.
+#ifdef MTEXTCONTROL_EXPORTS
+ #define DLL_API __declspec(dllexport)
+#else
+ #define DLL_API __declspec(dllimport)
+#endif // MTEXTCONTROL_EXPORTS
+
+#ifndef MTEXT_NOHELPERS
+ #define MTEXT_NOHELPERS
+#endif // MTEXT_NOHELPERS
+ #include "m_text.h"
+
+// API for other plugins
+// #include "../api/m_popup.h"
+// #include "../api/m_popupw.h"
+ #include "m_mathmodule.h"
+ #include <m_smileyadd.h>
+// #include "../api/m_nconvers.h"
+// #include "../api/m_ticker.h"
+// #include "../api/m_avatars.h"
+#ifdef _cplusplus
+};
+#endif
+
+// globals
+extern HINSTANCE hInst;
+extern PLUGININFO pluginInfo;
+extern PLUGININFOEX pluginInfoEx;
+
+// dlls
+//#include "dlls.h"
+
+// Project headers
+#include "version.h"
+//#include "gdiutils.h"
+//#include "bitmap_funcs.h"
+//#include "icons.h"
+#include "services.h"
+#include "textusers.h"
+//#include "options.h"
+#include "richeditutils.h"
+//#include "IconOleObject.h"
+#include "ImageDataObjectHlp.h"
+#include "FormattedTextDraw.h"
+#include "fancy_rtf.h"
+//#include "fancy.h"
+#include "textcontrol.h"
+
+#endif // __headers_h__
diff --git a/plugins/mTextControl/src/main.cpp b/plugins/mTextControl/src/main.cpp new file mode 100644 index 0000000000..16dbc20015 --- /dev/null +++ b/plugins/mTextControl/src/main.cpp @@ -0,0 +1,143 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+
+Copyright © 2005 Victor Pavlychko (nullbie@gmail.com),
+ © 2010 Merlin_de
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: main.cpp $
+Revision : $Revision: $
+Last change on : $Date: 2010-07-03 15:25:00 $
+Last change by : $Author: Merlin_de $
+
+===============================================================================
+*/
+
+#include "headers.h"
+
+HINSTANCE hInst = 0;
+PLUGINLINK *pluginLink = 0;
+
+HMODULE hMsfteditDll = 0;
+HRESULT (WINAPI *MyCreateTextServices)(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk);
+
+PLUGININFOEX pluginInfoEx =
+{
+ sizeof(PLUGININFOEX),
+ MTEXT_DISPLAYNAME,
+ PLUGIN_MAKE_VERSION(__MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM),
+ MTEXT_DESCRIPTION,
+ MTEXT_AUTHOR,
+ MTEXT_EMAIL,
+ MTEXT_COPYRIGHT,
+ MTEXT_WEBPAGE,
+ UNICODE_AWARE,
+ 0,
+ MTEXT_UUID
+};
+
+PLUGININFO pluginInfo =
+{
+ sizeof(PLUGININFO),
+ pluginInfoEx.shortName,
+ pluginInfoEx.version,
+ pluginInfoEx.description,
+ pluginInfoEx.author,
+ pluginInfoEx.authorEmail,
+ pluginInfoEx.copyright,
+ pluginInfoEx.homepage,
+ pluginInfoEx.flags,
+ pluginInfoEx.replacesDefaultModule
+};
+
+extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
+{
+ hInst=hinstDLL;
+ return TRUE;
+}
+
+static HANDLE hModulesLoaded = 0;
+static int ModulesLoaded(WPARAM wParam,LPARAM lParam);
+
+extern "C" __declspec(dllexport) PLUGININFO *MirandaPluginInfo(DWORD mirandaVersion)
+{
+ pluginInfo.cbSize = sizeof(PLUGININFO);
+ return &pluginInfo;
+}
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ pluginInfoEx.cbSize = sizeof(PLUGININFOEX);
+ return &pluginInfoEx;
+}
+
+extern "C" __declspec(dllexport) const MUUID *MirandaPluginInterfaces(void)
+{
+ static const MUUID interfaces[] = { MTEXT_UUID, MIID_LAST };
+ return interfaces;
+}
+
+extern "C" __declspec(dllexport) int Load(PLUGINLINK *link)
+{
+ pluginLink = link;
+
+ //6.0A SDK is missing RichEd20.lib for x64
+ //http://connect.microsoft.com/VisualStudio/feedback/details/551071/the-6-0a-sdk-is-missing-riched20-lib-for-x64
+ MyCreateTextServices = 0;
+ hMsfteditDll = LoadLibrary(_T("msftedit.dll"));
+ if (hMsfteditDll) {
+ MyCreateTextServices = (HRESULT (WINAPI *)(
+ IUnknown *punkOuter,
+ ITextHost *pITextHost,
+ IUnknown **ppUnk))
+ GetProcAddress(hMsfteditDll, "CreateTextServices");
+ }
+
+// LoadFancy();
+ LoadEmfCache();
+ LoadRichEdit();
+ LoadTextUsers();
+ LoadServices();
+ //LoadOptions();
+
+ MTextControl_RegisterClass();
+ hModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
+ return 0;
+}
+
+static int ModulesLoaded(WPARAM wParam,LPARAM lParam)
+{
+// char fn[MAX_PATH+1];
+// GetModuleFileName(hInst, fn, MAX_PATH);
+// InitFancy();
+// InitIcons(icons, fn, iconCount);
+ return 0;
+}
+
+extern "C" __declspec(dllexport) int Unload(void)
+{
+ UnhookEvent(hModulesLoaded);
+// UnloadOptions();
+ UnloadServices();
+ UnloadTextUsers();
+ UnloadRichEdit();
+ UnloadEmfCache();
+// UnloadFancy();
+ FreeLibrary(hMsfteditDll);
+ return 0;
+}
diff --git a/plugins/mTextControl/src/richeditutils.cpp b/plugins/mTextControl/src/richeditutils.cpp new file mode 100644 index 0000000000..28a267654b --- /dev/null +++ b/plugins/mTextControl/src/richeditutils.cpp @@ -0,0 +1,164 @@ +#include "headers.h"
+
+class CREOleCallback: public IRichEditOleCallback
+{
+private:
+ unsigned refCount;
+ IStorage *pictStg;
+ int nextStgId;
+public:
+ CREOleCallback()
+ {
+ refCount = 1;
+ pictStg = 0;
+ nextStgId = 0;
+ }
+
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID * ppvObj)
+ {
+ if (IsEqualIID(riid, IID_IRichEditOleCallback))
+ {
+ *ppvObj = this;
+ this->AddRef();
+ return S_OK;
+ }
+ *ppvObj = NULL;
+ return E_NOINTERFACE;
+ }
+
+ ULONG STDMETHODCALLTYPE AddRef()
+ {
+ if (this->refCount == 0) {
+ if (S_OK != StgCreateDocfile(NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_DELETEONRELEASE, 0, &this->pictStg))
+ this->pictStg = NULL;
+ this->nextStgId = 0;
+ }
+ return ++this->refCount;
+ }
+
+ ULONG STDMETHODCALLTYPE Release()
+ {
+ if (--this->refCount == 0) {
+ if (this->pictStg)
+ this->pictStg->Release();
+ }
+ return this->refCount;
+ }
+
+ HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE DeleteObject(LPOLEOBJECT lpoleobj)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetClipboardData(CHARRANGE * lpchrg, DWORD reco, LPDATAOBJECT * lplpdataobj)
+ {
+ return E_NOTIMPL;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetContextMenu(WORD seltype, LPOLEOBJECT lpoleobj, CHARRANGE * lpchrg, HMENU * lphmenu)
+ {
+ return E_INVALIDARG;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetDragDropEffect(BOOL fDrag, DWORD grfKeyState, LPDWORD pdwEffect)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetInPlaceContext(LPOLEINPLACEFRAME * lplpFrame, LPOLEINPLACEUIWINDOW * lplpDoc, LPOLEINPLACEFRAMEINFO lpFrameInfo)
+ {
+ return E_INVALIDARG;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetNewStorage(LPSTORAGE * lplpstg)
+ {
+ WCHAR szwName[64];
+ char szName[64];
+ wsprintfA(szName, "s%u", this->nextStgId);
+ MultiByteToWideChar(CP_ACP, 0, szName, -1, szwName, sizeof(szwName) / sizeof(szwName[0]));
+ if (this->pictStg == NULL)
+ return STG_E_MEDIUMFULL;
+#ifdef UNICODE
+ return this->pictStg->CreateStorage(szwName, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, lplpstg);
+#else
+ return this->pictStg->CreateStorage(szName, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, lplpstg);
+#endif
+ }
+
+ HRESULT STDMETHODCALLTYPE QueryAcceptData(LPDATAOBJECT lpdataobj, CLIPFORMAT * lpcfFormat, DWORD reco, BOOL fReally, HGLOBAL hMetaPict)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE QueryInsertObject(LPCLSID lpclsid, LPSTORAGE lpstg, LONG cp)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE ShowContainerUI(BOOL fShow)
+ {
+ return S_OK;
+ }
+};
+
+IRichEditOleCallback *reOleCallback = 0;
+
+void InitRichEdit(ITextServices *ts)
+{
+ LRESULT lResult;
+ ts->TxSendMessage(EM_SETOLECALLBACK, 0, (LPARAM)reOleCallback, &lResult);
+}
+
+LRESULT CALLBACK RichEditProxyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ ITextServices *ts = (ITextServices *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ if (ts && (msg != WM_DESTROY))
+ {
+ LRESULT lResult;
+ ts->TxSendMessage(msg, wParam, lParam, &lResult);
+ return lResult;
+ }
+ return 1;
+}
+
+void LoadRichEdit()
+{
+ OleInitialize(NULL);
+// LoadLibrary("riched20.dll");
+ reOleCallback = new CREOleCallback;
+// CoInitializeEx(NULL,COINIT_MULTITHREADED);
+
+
+ WNDCLASSEX wcl;
+ wcl.cbSize = sizeof(wcl);
+ wcl.lpfnWndProc = RichEditProxyWndProc;
+ wcl.style = CS_GLOBALCLASS;
+ wcl.cbClsExtra = 0;
+ wcl.cbWndExtra = 0;
+ wcl.hInstance = hInst;
+ wcl.hIcon = NULL;
+ wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
+ wcl.lpszMenuName = NULL;
+ wcl.lpszClassName = _T("NBRichEditProxyWndClass");
+ wcl.hIconSm = 0;
+ RegisterClassEx(&wcl);
+}
+
+void UnloadRichEdit()
+{
+ delete reOleCallback;
+ OleUninitialize();
+}
+
+HWND CreateProxyWindow(ITextServices *ts)
+{
+ HWND hwnd = CreateWindow(_T("NBRichEditProxyWndClass"), _T(""), 0, 0, 0, 0, 0, 0, 0, hInst, 0);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ts);
+ return hwnd;
+}
diff --git a/plugins/mTextControl/src/richeditutils.h b/plugins/mTextControl/src/richeditutils.h new file mode 100644 index 0000000000..a459f62f6a --- /dev/null +++ b/plugins/mTextControl/src/richeditutils.h @@ -0,0 +1,12 @@ +#ifndef __richeditutils_h__
+#define __richeditutils_h__
+
+extern IRichEditOleCallback *reOleCallback;
+
+void LoadRichEdit();
+void UnloadRichEdit();
+
+void InitRichEdit(ITextServices *ts);
+HWND CreateProxyWindow(ITextServices *ts);
+
+#endif // __richeditutils_h__
diff --git a/plugins/mTextControl/src/services.cpp b/plugins/mTextControl/src/services.cpp new file mode 100644 index 0000000000..cb0b2a9e48 --- /dev/null +++ b/plugins/mTextControl/src/services.cpp @@ -0,0 +1,382 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "headers.h"
+
+static HANDLE hService[11] = {0,0,0,0,0,0,0,0,0,0,0};
+
+INT_PTR MText_Register(WPARAM, LPARAM);
+INT_PTR MText_Create(WPARAM, LPARAM);
+INT_PTR MText_CreateW(WPARAM, LPARAM);
+INT_PTR MText_CreateEx(WPARAM, LPARAM);
+INT_PTR MText_Measure(WPARAM, LPARAM);
+INT_PTR MText_Display(WPARAM, LPARAM);
+INT_PTR MText_SetParent(WPARAM, LPARAM);
+INT_PTR MText_SendMessage(WPARAM, LPARAM);
+INT_PTR MText_CreateProxy(WPARAM, LPARAM);
+INT_PTR MText_Destroy(WPARAM, LPARAM);
+INT_PTR MText_GetInterface(WPARAM, LPARAM);
+
+struct TextObject
+{
+ DWORD options;
+ IFormattedTextDraw *ftd;
+ TextObject(): options(0), ftd(0) {}
+ ~TextObject() { if (ftd) delete ftd; }
+};
+
+//---------------------------------------------------------------------------
+// elper functions
+void MText_InitFormatting0(IFormattedTextDraw *ftd, DWORD options) {
+ LRESULT lResult;
+
+ // urls
+ ftd->getTextService()->TxSendMessage(EM_AUTOURLDETECT, TRUE, 0, &lResult);
+}
+
+void MText_InitFormatting1(TextObject *text) {
+ // bbcodes
+ bbCodeParse(text->ftd);
+
+ // smilies
+// HWND hwnd = (HWND)CallServiceSync(MS_TEXT_CREATEPROXY, (WPARAM)text, (LPARAM)0);
+ HWND hwnd = CreateProxyWindow(text->ftd->getTextService());
+ SMADD_RICHEDIT3 sm = {0};
+ sm.cbSize = sizeof(sm);
+ sm.hwndRichEditControl = hwnd;
+ sm.rangeToReplace = 0;
+ sm.Protocolname = 0;
+ sm.flags = SAFLRE_INSERTEMF;
+ CallService(MS_SMILEYADD_REPLACESMILEYS, RGB(0xff, 0xff, 0xff), (LPARAM)&sm);
+ DestroyWindow(hwnd);
+
+// text->ftd->getTextService()->TxSendMessage(EM_SETSEL, 0, -1, &lResult);
+/*
+ // rtl stuff
+ PARAFORMAT2 pf2;
+ pf2.cbSize = sizeof(pf2);
+ pf2.dwMask = PFM_ALIGNMENT|PFM_RTLPARA;
+ pf2.wEffects = PFE_RTLPARA;
+ pf2.wAlignment = PFA_RIGHT;
+ text->ftd->getTextService()->TxSendMessage(EM_SETSEL, 0, -1, &lResult);
+ text->ftd->getTextService()->TxSendMessage(EM_SETPARAFORMAT, 0, (LPARAM)&pf2, &lResult);
+ text->ftd->getTextService()->TxSendMessage(EM_SETSEL, 0, 0, &lResult);
+*/
+}
+
+//---------------------------------------------------------------------------
+// NEW mtextcontrol interface:
+//
+// obtain the full mtextcontrol interface from the library. it is much faster as use of
+// miranda core CallService to access to mtextcontrol (no core traffic).
+// This interface provides full access to mtextcontrol internal functions,
+// thus enabling devs to fully utilize the mtextcontrol API.
+// All functions will be exported as miranda services for compatibility.
+//
+// the interface is populated during the Load(PLUGINLINK *link) handler, so you can assume it is ready when Miranda
+// throw the ME_SYSTEM_MODULESLOADED event and you can generate a warning in your ModulesLoaded() when
+// it depends on the mtextcontrol interface and the mtextcontrol plugin is missing.
+//
+// example:
+//
+// MTEXT_INTERFACE MText = {0};
+//
+// mir_getMTI(&MText);
+//
+// all interface function designed as old mtextcontrol helper functions.
+// therefore it is easy to convert your old plugin code to new interface.
+//
+// example:
+//
+// old code: MTextCreate (...
+// new code: MText.Create(...
+
+//---------------------------------------------------------------------------
+// subscribe to MText services
+INT_PTR MText_Register(WPARAM wParam, LPARAM lParam)
+{
+ DWORD userOptions = (DWORD)wParam;
+ char *userTitle = (char *)lParam;
+ return (INT_PTR)MTI_TextUserAdd(userTitle, userOptions);
+}
+
+//---------------------------------------------------------------------------
+// allocate text object
+HANDLE DLL_CALLCONV
+MTI_MTextCreate (HANDLE userHandle, char *text) {
+ TextObject *result = new TextObject;
+ result->options = TextUserGetOptions(userHandle);
+ result->ftd = new CFormattedTextDraw;
+ result->ftd->Create();
+ InitRichEdit(result->ftd->getTextService());
+
+ MText_InitFormatting0(result->ftd, result->options);
+ result->ftd->putTextA(text);
+ MText_InitFormatting1(result);
+
+ return (HANDLE)result;
+}
+
+INT_PTR MText_Create(WPARAM wParam, LPARAM lParam) {
+ //HANDLE userHandle = (HANDLE)wParam;
+ //char *text = (char *)lParam;
+ return (INT_PTR)MTI_MTextCreate ((HANDLE)wParam, (char *)lParam);
+}
+
+//---------------------------------------------------------------------------
+// allocate text object (unicode)
+HANDLE DLL_CALLCONV
+MTI_MTextCreateW (HANDLE userHandle, WCHAR *text) {
+#ifdef UNICODE
+ TextObject *result = new TextObject;
+ result->options = TextUserGetOptions(userHandle);
+ result->ftd = new CFormattedTextDraw;
+ result->ftd->Create();
+ InitRichEdit(result->ftd->getTextService());
+
+ MText_InitFormatting0(result->ftd, result->options);
+ result->ftd->putTextW(text);
+ MText_InitFormatting1(result);
+
+ return (HANDLE)result;
+#else
+ return 0;
+#endif
+}
+
+INT_PTR MText_CreateW(WPARAM wParam, LPARAM lParam) {
+#ifdef UNICODE
+ //HANDLE userHandle = (HANDLE)wParam;
+ //WCHAR *wtext = (WCHAR *)lParam;
+ return (INT_PTR)(HANDLE)MTI_MTextCreateW ((HANDLE)wParam, (WCHAR *)lParam);
+#else
+ return 0;
+#endif
+}
+
+//---------------------------------------------------------------------------
+// allocate text object (advanced)
+HANDLE DLL_CALLCONV
+MTI_MTextCreateEx (HANDLE userHandle, HANDLE hContact, void *text, DWORD flags) {
+ TextObject *result = new TextObject;
+ result->options = TextUserGetOptions(userHandle);
+ result->ftd = new CFormattedTextDraw;
+ result->ftd->Create();
+ InitRichEdit(result->ftd->getTextService());
+
+ MText_InitFormatting0(result->ftd, result->options);
+ if (flags & MTEXT_FLG_WCHAR) result->ftd->putTextW((WCHAR *)text);
+ else result->ftd->putTextA((char *)text);
+ MText_InitFormatting1(result);
+
+ return 0;
+}
+
+INT_PTR MText_CreateEx(WPARAM wParam, LPARAM lParam) {
+ HANDLE userHandle = (HANDLE)wParam;
+ MTEXTCREATE *textCreate = (MTEXTCREATE *)lParam;
+ MTI_MTextCreateEx (userHandle, textCreate->hContact, textCreate->text, textCreate->flags);
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+// measure text object
+int DLL_CALLCONV
+MTI_MTextMeasure (HDC dc, SIZE *sz, HANDLE text) {
+ if (!text) return 0;
+
+ long lWidth=sz->cx, lHeight=sz->cy;
+ ((TextObject *)text)->ftd->get_NaturalSize(dc, &lWidth, &lHeight);
+ sz->cx = lWidth;
+ sz->cy = lHeight;
+// FancyMeasure(((TextObject *)text)->fancy, displayInfo);
+
+ return 0;
+}
+
+INT_PTR MText_Measure(WPARAM wParam, LPARAM lParam) {
+ LPMTEXTDISPLAY displayInfo = (LPMTEXTDISPLAY)wParam;
+ if (!displayInfo) return 0;
+ if (!(TextObject *)displayInfo->text) return 0;
+ MTI_MTextMeasure (displayInfo->dc, &displayInfo->sz, displayInfo->text);
+ return 0;
+}
+
+int DLL_CALLCONV
+//---------------------------------------------------------------------------
+// display text object
+MTI_MTextDisplay (HDC dc, POINT pos, SIZE sz, HANDLE text) {
+ if (!text) return 0;
+
+ COLORREF cl = GetTextColor(dc);
+// if (GetTextColor(dc)&0xffffff != 0)
+ {
+ LRESULT lResult;
+ CHARFORMAT cf = {0};
+ cf.cbSize = sizeof(cf);
+ cf.dwMask = CFM_COLOR;
+ cf.crTextColor = cl;
+ ((TextObject *)text)->ftd->getTextService()->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult);
+ }
+
+ SetBkMode(dc, TRANSPARENT);
+
+ long lWidth=sz.cx, lHeight;
+ ((TextObject *)text)->ftd->get_NaturalSize(dc, &lWidth, &lHeight);
+ RECT rt;
+ rt.left = pos.x;
+ rt.top = pos.y;
+ rt.right = pos.x + lWidth;
+ rt.bottom = pos.y + lHeight;
+ ((TextObject *)text)->ftd->Draw(dc, &rt);
+
+ return 0;
+}
+
+INT_PTR MText_Display(WPARAM wParam, LPARAM lParam) {
+ LPMTEXTDISPLAY displayInfo = (LPMTEXTDISPLAY)wParam;
+ if (!displayInfo) return 0;
+ if (!displayInfo->text) return 0;
+ MTI_MTextDisplay (displayInfo->dc, displayInfo->pos, displayInfo->sz, displayInfo->text);
+ return 0;
+}
+
+int DLL_CALLCONV
+//---------------------------------------------------------------------------
+// set parent window for text object (this is required for mouse handling, etc)
+MTI_MTextSetParent (HANDLE text, HWND hwnd, RECT rect) {
+ if (!text) return 0;
+ ((TextObject *)text)->ftd->setParentWnd(hwnd, rect);
+ return 0;
+}
+
+INT_PTR MText_SetParent(WPARAM wParam, LPARAM lParam) {
+ LPMTEXTSETPARENT info = (LPMTEXTSETPARENT)wParam;
+ //TextObject *text = (TextObject *)info->text;
+ if (!info) return 0;
+ if (!info->text) return 0;
+ MTI_MTextSetParent (info->text, info->hwnd, info->rc);
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+// send message to an object
+int DLL_CALLCONV
+MTI_MTextSendMessage (HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam) {
+ LRESULT lResult;
+ if (!text) return 0;
+ ((TextObject *)text)->ftd->getTextService()->TxSendMessage(msg, wParam, lParam, &lResult);
+
+ if (hwnd && (msg == WM_MOUSEMOVE)) {
+ HDC hdc = GetDC(hwnd);
+ ((TextObject *)text)->ftd->getTextService()->OnTxSetCursor(DVASPECT_CONTENT, 0, NULL, NULL, hdc, NULL, NULL, LOWORD((LPARAM)0), HIWORD((LPARAM)0));
+ ReleaseDC(hwnd, hdc);
+ }
+
+ return lResult;
+}
+
+INT_PTR MText_SendMessage(WPARAM wParam, LPARAM lParam) {
+ LPMTEXTMESSAGE message = (LPMTEXTMESSAGE)wParam;
+ TextObject *text = (TextObject *)message->text;
+ if (!message->text) return 0;
+ return (INT_PTR)MTI_MTextSendMessage (message->hwnd, message->text, message->msg, message->wParam, message->lParam);
+}
+
+//---------------------------------------------------------------------------
+// create a proxy window
+HWND DLL_CALLCONV
+MTI_MTextCreateProxy (HANDLE text) {
+ if (!text) return 0;
+ return CreateProxyWindow(((TextObject *)text)->ftd->getTextService());
+}
+
+INT_PTR MText_CreateProxy(WPARAM wParam, LPARAM lParam) {
+ if (!wParam) return 0;
+ return (INT_PTR)MTI_MTextCreateProxy((HANDLE)wParam);
+}
+
+int DLL_CALLCONV
+//---------------------------------------------------------------------------
+// destroy text object
+MTI_MTextDestroy (HANDLE text) {
+ //HANDLE textHandle = (HANDLE)wParam;
+ //TextObject *text = (TextObject *)textHandle;
+ if (text) delete (TextObject *)text;
+ return 0;
+}
+
+INT_PTR MText_Destroy(WPARAM wParam, LPARAM lParam) {
+ HANDLE textHandle = (HANDLE)wParam;
+ TextObject *text = (TextObject *)textHandle;
+ if (text) delete text;
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+// populate the interface
+INT_PTR MText_GetInterface(WPARAM wParam, LPARAM lParam) {
+ MTEXT_INTERFACE *MText = (MTEXT_INTERFACE *)lParam;
+ if ( MText == NULL )
+ return CALLSERVICE_NOTFOUND;
+
+ MText->version = pluginInfo.version;
+ MText->Register = MTI_TextUserAdd;
+ MText->Create = MTI_MTextCreate;
+ MText->CreateW = MTI_MTextCreateW;
+// MText->CreateT = defined inside api
+ MText->CreateEx = MTI_MTextCreateEx;
+ MText->Measure = MTI_MTextMeasure;
+ MText->Display = MTI_MTextDisplay;
+ MText->SetParent = MTI_MTextSetParent;
+ MText->SendMsg = MTI_MTextSendMessage;
+ MText->CreateProxy = MTI_MTextCreateProxy;
+ MText->Destroy = MTI_MTextDestroy;
+
+ return S_OK;
+}
+
+//---------------------------------------------------------------------------
+// Load / Unload services
+void LoadServices()
+{
+ int nService = 0;
+ hService[nService++] = CreateServiceFunction(MS_TEXT_REGISTER, MText_Register);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_CREATE, MText_Create);
+#ifdef UNICODE
+ hService[nService++] = CreateServiceFunction(MS_TEXT_CREATEW, MText_CreateW);
+#endif
+ hService[nService++] = CreateServiceFunction(MS_TEXT_CREATEEX, MText_CreateEx);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_MEASURE, MText_Measure);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_DISPLAY, MText_Display);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_SETPARENT, MText_SetParent);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_SENDMESSAGE, MText_SendMessage);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_CREATEPROXY, MText_CreateProxy);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_DESTROY, MText_Destroy);
+ hService[nService++] = CreateServiceFunction(MS_TEXT_GETINTERFACE, MText_GetInterface);
+}
+
+void UnloadServices()
+{
+ int nService = sizeof(hService)/sizeof(*hService);
+ while (nService--)
+ if (hService[nService])
+ DestroyServiceFunction(hService[nService]);
+}
+
diff --git a/plugins/mTextControl/src/services.h b/plugins/mTextControl/src/services.h new file mode 100644 index 0000000000..28917834a1 --- /dev/null +++ b/plugins/mTextControl/src/services.h @@ -0,0 +1,36 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __services_h__
+#define __services_h__
+
+void LoadServices();
+void UnloadServices();
+
+DLL_API HANDLE DLL_CALLCONV MTI_MTextCreate (HANDLE userHandle, char *text);
+DLL_API HANDLE DLL_CALLCONV MTI_MTextCreateW (HANDLE userHandle, WCHAR *text);
+DLL_API HANDLE DLL_CALLCONV MTI_MTextCreateEx (HANDLE userHandle, HANDLE hContact, void *text, DWORD flags);
+DLL_API int DLL_CALLCONV MTI_MTextMeasure (HDC dc, SIZE *sz, HANDLE text);
+DLL_API int DLL_CALLCONV MTI_MTextDisplay (HDC dc, POINT pos, SIZE sz, HANDLE text);
+DLL_API int DLL_CALLCONV MTI_MTextSetParent (HANDLE text, HWND hwnd, RECT rect);
+DLL_API int DLL_CALLCONV MTI_MTextSendMessage (HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam);
+DLL_API HWND DLL_CALLCONV MTI_MTextCreateProxy (HANDLE text);
+DLL_API int DLL_CALLCONV MTI_MTextDestroy (HANDLE text);
+
+#endif // __services_h__
diff --git a/plugins/mTextControl/src/textcontrol.cpp b/plugins/mTextControl/src/textcontrol.cpp new file mode 100644 index 0000000000..29caf2eb0a --- /dev/null +++ b/plugins/mTextControl/src/textcontrol.cpp @@ -0,0 +1,200 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "headers.h"
+
+LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT MTextControl_OnPaint(HWND hwnd, WPARAM wParam, LPARAM lParam);
+//LRESULT MTextControl_Measure(HWND hwnd, int maxw, SIZE *size);
+
+struct TextControlData
+{
+ HANDLE htu;
+ TCHAR *text;
+ HANDLE mtext;
+};
+
+void MTextControl_RegisterClass()
+{
+ WNDCLASSEX wcl;
+ wcl.cbSize = sizeof(wcl);
+ wcl.lpfnWndProc = MTextControlWndProc;
+ wcl.style = CS_GLOBALCLASS;
+ wcl.cbClsExtra = 0;
+ wcl.cbWndExtra = 0;
+ wcl.hInstance = hInst;
+ wcl.hIcon = NULL;
+ wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
+ wcl.lpszMenuName = NULL;
+ wcl.lpszClassName = _T(MODULNAME);
+ wcl.hIconSm = 0;
+ RegisterClassEx(&wcl);
+}
+
+LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ TextControlData *data = (TextControlData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ switch(msg)
+ {
+ case WM_CREATE:
+ {
+ data = new TextControlData;
+ data->text = 0;
+ data->mtext = 0;
+ data->htu = htuDefault;
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data);
+ PostMessage(hwnd, MTM_UPDATE, 0, 0);
+ return 0;
+ }
+
+ case MTM_SETUSER:
+ {
+ data->htu = wParam ? (HANDLE)wParam : htuDefault;
+ // falldown, DefWindowProc won't process WM_USER ;)
+ }
+
+ case WM_SETTEXT:
+ {
+ DefWindowProc(hwnd, msg, wParam, lParam);
+ // falldown
+ }
+
+ case MTM_UPDATE:
+ {
+ if (data->text) delete [] data->text;
+ if (data->mtext) MTI_MTextDestroy(data->mtext);
+
+ int textLength = GetWindowTextLength(hwnd);
+ data->text = new TCHAR[textLength+1];
+ GetWindowText(hwnd, data->text, textLength+1);
+ #if defined(UNICODE) || defined (_UNICODE)
+ data->mtext = MTI_MTextCreateW(data->htu, data->text);
+ #else
+ data->mtext = MTI_MTextCreate(data->htu, data->text);
+ #endif
+
+ RECT rc; GetClientRect(hwnd, &rc);
+ MTI_MTextSetParent(data->mtext, hwnd, rc);
+
+ InvalidateRect(hwnd, 0, TRUE);
+
+ return TRUE;
+ }
+
+ case WM_PAINT:
+ {
+ return MTextControl_OnPaint(hwnd, wParam, lParam);
+ }
+
+ case WM_ERASEBKGND:
+ {
+ HDC hdc = (HDC)wParam;
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+ FillRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
+ return TRUE;
+ }
+
+// case WM_NCHITTEST:
+// case WM_NCMOUSEMOVE:
+ case WM_MOUSEMOVE:
+// case WM_LBUTTONDOWN:
+// case WM_LBUTTONUP:
+// case WM_RBUTTONDOWN:
+// case WM_RBUTTONUP:
+ {
+ if (data && data->mtext)
+ return MTI_MTextSendMessage(hwnd, data->mtext, msg, wParam, lParam);
+ break;
+ }
+
+ }
+
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+}
+
+/// Paint ////////////////////////////////////
+LRESULT MTextControl_OnPaint(HWND hwnd, WPARAM wParam, LPARAM lParam)
+{
+ HDC hdc;
+ PAINTSTRUCT ps;
+ hdc = BeginPaint(hwnd, &ps);
+
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+ FrameRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
+
+ SetTextColor(hdc, RGB(0,0,0));
+ SetBkMode(hdc, TRANSPARENT);
+
+ // Find the text to draw
+ TextControlData *data = (TextControlData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ if (data->mtext)
+ {
+/*
+ // Font-related stuff
+ LOGFONT lfText;
+ lfText.lfHeight = -11; //"8" in the font dialog
+ lfText.lfWidth = lfText.lfEscapement = lfText.lfOrientation = 0;
+ lfText.lfItalic = lfText.lfUnderline = lfText.lfStrikeOut = FALSE;
+ lfText.lfCharSet = DEFAULT_CHARSET;
+ lfText.lfOutPrecision = OUT_DEFAULT_PRECIS;
+ lfText.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ lfText.lfQuality = DEFAULT_QUALITY;
+ lfText.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
+ lstrcpy(lfText.lfFaceName,_T("Tahoma"));
+ lfText.lfWeight = FW_REGULAR;
+ HFONT hfntSave = (HFONT)SelectObject(hdc, CreateFontIndirect(&lfText));
+*/
+
+ HFONT hfntSave = 0;
+ HFONT hfnt = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
+ if (!hfnt)
+ hfnt = (HFONT)SendMessage(GetParent(hwnd), WM_GETFONT, 0, 0);
+ if (hfnt)
+ {
+ LOGFONT lf;
+ GetObject(hfnt, sizeof(lf), &lf);
+ hfntSave = (HFONT)SelectObject(hdc, hfnt);
+ }
+
+ // Draw the text
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+ POINT pos;
+ pos.x = 0;
+ pos.y = 2;
+ SIZE sz;
+ sz.cx = rc.right - rc.left;
+ sz.cy = rc.bottom - rc.top - 4;
+ MTI_MTextDisplay(hdc, pos, sz, data->mtext);
+
+ if (hfntSave)
+ SelectObject(hdc, hfntSave);
+
+// DeleteObject(SelectObject(hdc, hfntSave));
+
+ }
+
+ // Release the device context
+ EndPaint(hwnd, &ps);
+
+ return 0;
+}
diff --git a/plugins/mTextControl/src/textcontrol.h b/plugins/mTextControl/src/textcontrol.h new file mode 100644 index 0000000000..ef694263ae --- /dev/null +++ b/plugins/mTextControl/src/textcontrol.h @@ -0,0 +1,25 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __textcontrol_h__
+#define __textcontrol_h__
+
+void MTextControl_RegisterClass();
+
+#endif // __textcontrol_h__
\ No newline at end of file diff --git a/plugins/mTextControl/src/textusers.cpp b/plugins/mTextControl/src/textusers.cpp new file mode 100644 index 0000000000..60b849252a --- /dev/null +++ b/plugins/mTextControl/src/textusers.cpp @@ -0,0 +1,88 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "headers.h"
+
+HANDLE htuDefault = 0;
+
+TextUser *textUserFirst=0;
+TextUser *textUserLast=0;
+
+void LoadTextUsers()
+{
+ htuDefault = MTI_TextUserAdd("Text Controls", MTEXT_FANCY_MASK);
+}
+
+void UnloadTextUsers()
+{
+ while (textUserFirst)
+ {
+ delete [] textUserFirst->name;
+ TextUser *next = textUserFirst->next;
+ delete [] textUserFirst;
+ textUserFirst = next;
+ }
+}
+
+HANDLE DLL_CALLCONV
+MTI_TextUserAdd(const char *userTitle, DWORD options)
+{
+ TextUser *textUserNew = new TextUser;
+ textUserNew->name = new char [lstrlenA(userTitle)+1];
+ lstrcpyA(textUserNew->name, userTitle);
+ textUserNew->options =
+ (DBGetContactSettingDword(0, MODULNAME, userTitle, options)&MTEXT_FANCY_MASK) | (textUserNew->options&MTEXT_SYSTEM_MASK);
+ DBWriteContactSettingDword(0, MODULNAME, userTitle, textUserNew->options);
+ textUserNew->prev = textUserLast;
+ textUserNew->next = 0;
+ if (textUserLast)
+ {
+ textUserLast->next = textUserNew;
+ textUserLast = textUserNew;
+ } else
+ {
+ textUserFirst = textUserLast = textUserNew;
+ }
+ return (HANDLE)textUserNew;
+}
+
+DWORD TextUserGetOptions(HANDLE userHandle)
+{
+ if (!userHandle) return 0;
+ return ((TextUser *)userHandle)->options;
+}
+
+void TextUserSetOptions(HANDLE userHandle, DWORD options)
+{
+ if (!userHandle) return;
+ ((TextUser *)userHandle)->options = options;
+}
+
+void TextUsersSave()
+{
+ for (TextUser *textUser = textUserFirst; textUser; textUser = textUser->next)
+ DBWriteContactSettingDword(0, MODULNAME, textUser->name, textUser->options);
+}
+
+void TextUsersReset()
+{
+ for (TextUser *textUser = textUserFirst; textUser; textUser = textUser->next)
+ textUser->options =
+ (DBGetContactSettingDword(0, MODULNAME, textUser->name, 0)&MTEXT_FANCY_MASK) | (textUser->options&MTEXT_SYSTEM_MASK);
+}
diff --git a/plugins/mTextControl/src/textusers.h b/plugins/mTextControl/src/textusers.h new file mode 100644 index 0000000000..a0d135bbe8 --- /dev/null +++ b/plugins/mTextControl/src/textusers.h @@ -0,0 +1,47 @@ +/*
+Miranda Text Control - Plugin for Miranda IM
+Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __textusers_h__
+#define __textusers_h__
+
+#define MTEXT_GUI_MASK (MTEXT_BIDI_MASK|MTEXT_FANCY_SMILEYS|MTEXT_FANCY_BBCODES|MTEXT_FANCY_MATHMOD)
+
+struct TextUser
+{
+ char *name;
+ DWORD options;
+ TextUser *prev, *next;
+};
+
+extern TextUser *textUserFirst;
+extern TextUser *textUserLast;
+
+void LoadTextUsers();
+void UnloadTextUsers();
+
+extern HANDLE htuDefault;
+
+DLL_API HANDLE DLL_CALLCONV MTI_TextUserAdd(const char *userTitle, DWORD options);
+
+DWORD TextUserGetOptions(HANDLE userHandle);
+void TextUserSetOptions(HANDLE userHandle, DWORD options);
+void TextUsersSave();
+void TextUsersReset();
+
+#endif // __textusers_h__
diff --git a/plugins/mTextControl/src/version.h b/plugins/mTextControl/src/version.h new file mode 100644 index 0000000000..59e8525d63 --- /dev/null +++ b/plugins/mTextControl/src/version.h @@ -0,0 +1,60 @@ +/*
+Popup Plus plugin for Miranda IM
+
+Copyright © 2002 Luca Santarelli,
+ © 2005-2007 Victor Pavlychko
+ © 2010 Merlin_de
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL$
+Revision : $Revision$
+Last change on : $Date$
+Last change by : $Author$
+
+===============================================================================
+*/
+ #define MODULNAME "MTextControl" //DB modul for this plugin
+ #define MODULTITLE "Text Display"
+
+ #ifdef _UNICODE
+ #define MTEXT_DISPLAYNAME "Miranda Text Control (Unicode)"
+ #define MTEXT_FILENAME "mtextcontrolW.dll"
+ #else
+ #define MTEXT_DISPLAYNAME "Miranda Text Control (Ansi)"
+ #define MTEXT_FILENAME "mtextcontrol.dll"
+ #endif
+ #define __MAJOR_VERSION 0
+ #define __MINOR_VERSION 8
+ #define __RELEASE_NUM 0
+ #define __BUILD_NUM 1
+
+ #define __STRINGIFY(x) #x
+ #define __STRINGIFY2(x) __STRINGIFY(x)
+ #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
+ #define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM
+
+ #define __VERSION_STRING __STRINGIFY2(__FILEVERSION_STRING)
+ #define __VERSION_STRING_DOT __STRINGIFY2(__FILEVERSION_STRING_DOTS)
+
+ #define MTEXT_DESCRIPTION "Provides text render API for different plugins."
+ #define MTEXT_AUTHOR "Merlin_de, Victor Pavlychko"
+ #define MTEXT_EMAIL ""
+ #define MTEXT_COPYRIGHT "©2005-2006 Victor Pavlychko, ©2010 Merlin_de"
+ #define MTEXT_WEBPAGE "http://www.miranda-im.org/"
+ #define MTEXT_UUID {0x69b9443b, 0xdc58, 0x4876, { 0xad, 0x39, 0xe3, 0xf4, 0x18, 0xa1, 0x33, 0xc5 } }
+ //{69B9443B-DC58-4876-AD39-E3F418A133C5}
|