2#include "control/SRichEdit.h"
4#include "helper/SMenu.h"
5#include "helper/SplitString.h"
8#include <helper/STimer.h>
11#define LY_PER_INCH 1440
14#ifndef HIMETRIC_PER_INCH
15#define HIMETRIC_PER_INCH 2540
32 friend class SRichEdit;
37 SASSERT(s_textServiceHelper);
38 return s_textServiceHelper;
52 HRESULT
CreateTextServices(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk);
77 m_rich20 = LoadLibrary(_T(
"Msftedit.dll"));
79 m_rich20 = LoadLibrary(_T(
"libmsftedit.so"));
86 const char *err = dlerror();
87 printf(
"load so failed, err=%s\n", err);
106void SRichEdit::InitTextService()
108 SASSERT(s_textServiceHelper == NULL);
112void SRichEdit::UninitTextService()
114 SASSERT(s_textServiceHelper);
115 delete s_textServiceHelper;
116 s_textServiceHelper = NULL;
121class SRicheditDropTarget :
public IDropTarget {
123 SRicheditDropTarget(ITextServices *pTxtSvr)
131 ~SRicheditDropTarget()
138 virtual HRESULT STDMETHODCALLTYPE QueryInterface(
142 HRESULT hr = E_NOINTERFACE;
143 if (riid == __uuidof(IUnknown))
144 *ppvObject = (IUnknown *)
this, hr = S_OK;
145 else if (riid == __uuidof(IDropTarget))
146 *ppvObject = (IDropTarget *)
this, hr = S_OK;
152 virtual ULONG STDMETHODCALLTYPE AddRef(
void)
157 virtual ULONG STDMETHODCALLTYPE Release(
void)
166 virtual HRESULT STDMETHODCALLTYPE DragEnter(
167 IDataObject *pDataObj,
172 HRESULT hr = S_FALSE;
173 IDropTarget *pDropTarget = NULL;
174 hr = pserv->TxGetDropTarget(&pDropTarget);
177 hr = pDropTarget->DragEnter(pDataObj, grfKeyState, pt, pdwEffect);
178 *pdwEffect = DROPEFFECT_COPY;
179 pDropTarget->Release();
184 virtual HRESULT STDMETHODCALLTYPE DragOver(
189 HRESULT hr = S_FALSE;
190 IDropTarget *pDropTarget = NULL;
191 hr = pserv->TxGetDropTarget(&pDropTarget);
194 hr = pDropTarget->DragOver(grfKeyState, pt, pdwEffect);
195 *pdwEffect = DROPEFFECT_COPY;
196 pDropTarget->Release();
201 virtual HRESULT STDMETHODCALLTYPE DragLeave(
void)
203 HRESULT hr = S_FALSE;
204 IDropTarget *pDropTarget = NULL;
205 hr = pserv->TxGetDropTarget(&pDropTarget);
208 hr = pDropTarget->DragLeave();
209 pDropTarget->Release();
214 virtual HRESULT STDMETHODCALLTYPE Drop(
215 IDataObject *pDataObj,
220 if (*pdwEffect == DROPEFFECT_NONE)
222 HRESULT hr = S_FALSE;
223 IDropTarget *pDropTarget = NULL;
224 hr = pserv->TxGetDropTarget(&pDropTarget);
227 hr = pDropTarget->Drop(pDataObj, grfKeyState, pt, pdwEffect);
228 pDropTarget->Release();
234 ITextServices *pserv;
238const LONG cInitTextMax = (32 * 1024) - 1;
239#define FValidCF(_pcf) ((_pcf)->cbSize == sizeof(CHARFORMAT2W))
240#define FValidPF(_ppf) ((_ppf)->cbSize == sizeof(PARAFORMAT2))
241#define TIMER_INVALIDATE 6
243EXTERN_C
const IID IID_ITextServices =
244 { 0x8d33f740, 0xcf58, 0x11ce, { 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5 } };
246EXTERN_C
const IID IID_ITextHost =
247 { 0xc5bdd8d0, 0xd26e, 0x11ce, { 0xa8, 0x9e, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5 } };
250LONG DtoHimetric(LONG d, LONG dPerInch)
252 return (LONG)MulDiv(d, HIMETRIC_PER_INCH, dPerInch);
256LONG HimetrictoD(LONG lHimetric, LONG dPerInch)
258 return (LONG)MulDiv(lHimetric, dPerInch, HIMETRIC_PER_INCH);
268 friend class SRichEdit;
292 BOOL
Init(SRichEdit *pRichEdit);
305 STDMETHOD_(HRESULT, QueryInterface)(THIS_ REFGUID riid,
void **ppvObject) OVERRIDE;
306 STDMETHOD_(ULONG, AddRef)(THIS) OVERRIDE;
307 STDMETHOD_(ULONG, Release)(THIS) OVERRIDE;
360 virtual BOOL
TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw);
403 virtual BOOL
TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight);
435 virtual BOOL
TxSetTimer(UINT idTimer, UINT uTimeout);
460 virtual void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll);
487 virtual void TxSetCursor(HCURSOR hcur, BOOL fText);
679 virtual HRESULT
TxNotify(DWORD iNotify,
void *pv);
735HRESULT STextHost::QueryInterface(REFIID riid,
void **ppvObject)
737 HRESULT hr = E_NOINTERFACE;
740 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITextHost))
743 *ppvObject = (ITextHost *)
this;
750ULONG STextHost::AddRef(
void)
755ULONG STextHost::Release(
void)
757 ULONG c_Refs = --
cRefs;
812 return ::ClientToScreen(
m_pRichEdit->GetContainer()->GetHostHwnd(), lppt);
821 return ::ScreenToClient(
m_pRichEdit->GetContainer()->GetHostHwnd(), lppt);
854 return m_pRichEdit->OnTxSetTimer(idTimer, uTimeout);
859 m_ptCaret.x = x, m_ptCaret.y = y;
874 return m_pRichEdit->CreateCaret(hbmp, xWidth, yHeight);
879 return ::GetDC(NULL);
884 return ::ReleaseDC(NULL, hdc);
920 return m_pRichEdit->EnableScrollBar(wBar, fuArrowflags == ESB_ENABLE_BOTH);
925 return m_pRichEdit->SetScrollRange(fnBar != SB_HORZ, nMinPos, nMaxPos, fRedraw);
932 BOOL bVertical = fnBar != SB_HORZ;
933 SCROLLINFO *psi = bVertical ? (&m_siVer) : (&m_siHoz);
935 if (psi->nPos != nPos)
950 return m_pRichEdit->OnTxSetScrollPos(fnBar, nPos, fRedraw);
975 return ::GetSysColor(nIndex);
980 *pstyle = TXTBACK_TRANSPARENT;
992 *pdwScrollBar =
m_pRichEdit->m_dwStyle & (WS_VSCROLL | WS_HSCROLL | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_DISABLENOSCROLL);
1027 DWORD dwProperties = 0;
1031 dwProperties = TXTBIT_RICHTEXT;
1036 dwProperties |= TXTBIT_MULTILINE;
1041 dwProperties |= TXTBIT_READONLY;
1046 dwProperties |= TXTBIT_USEPASSWORD;
1051 dwProperties |= TXTBIT_HIDESELECTION;
1056 dwProperties |= TXTBIT_AUTOWORDSEL;
1061 dwProperties |= TXTBIT_VERTICAL;
1066 dwProperties |= TXTBIT_WORDWRAP;
1071 dwProperties |= TXTBIT_ALLOWBEEP;
1076 dwProperties |= TXTBIT_SAVESELECTION;
1079 *pdwBits = dwProperties & dwMask;
1090 return ImmGetContext(
m_pRichEdit->GetContainer()->GetHostHwnd());
1095 ImmReleaseContext(
m_pRichEdit->GetContainer()->GetHostHwnd(), himc);
1112 if (FAILED(STextServiceHelper::instance()->CreateTextServices(NULL,
this, &pUnk)))
1115 hr = pUnk->QueryInterface(IID_ITextServices, (
void **)&
pserv);
1119 return SUCCEEDED(hr);
1144 , m_dwStyle(ES_LEFT | ES_AUTOHSCROLL)
1147 m_pNcSkin = GETBUILTINSKIN(SKIN_SYS_BORDER);
1152 m_evtSet.addEvent(EVENTID(EventRENotify));
1153 m_evtSet.addEvent(EVENTID(EventREMenu));
1154 m_evtSet.addEvent(EVENTID(EventKeyDown));
1159 if (0 != __baseCls::OnCreate(NULL))
1175 m_style.m_crBg = RGB(0xff, 0xff, 0xff);
1177 m_pTxtHost->GetTextService()->OnTxInPlaceActivate(NULL);
1180 m_pTxtHost->GetTextService()->OnTxUIDeactivate();
1181 m_pTxtHost->GetTextService()->TxSendMessage(WM_KILLFOCUS, 0, 0, 0);
1185 dw |= IMF_AUTOKEYBOARD | IMF_DUALFONT | IMF_UIFONTS;
1186 dw &= ~IMF_AUTOFONT;
1210 m_pTxtHost->GetTextService()->OnTxInPlaceDeactivate();
1215 __baseCls::OnDestroy();
1231 GETRENDERFACTORY->CreateRenderTarget(&rt, rcClient.Width(), rcClient.Height());
1233 rt->SetViewportOrg(-rcClient.TopLeft());
1234 if (!SUCCEEDED(rt->BitBlt(&rcClient, pRT, rcClient.left, rcClient.top)))
1237 rt->ClearRect(&rcClient, RGBA(255, 255, 255, 255));
1245 HDC hdc = rt->GetDC(0);
1248 int nOldMode = ::SetGraphicsMode(hdc, GM_COMPATIBLE);
1252 CGdiAlpha::AlphaBackup(hdc, &rcClient, ai);
1255 m_pTxtHost->GetTextService()->TxGetVScroll(NULL, NULL, &lPos, NULL, NULL);
1256 RECTL rcL = { rcClient.left, rcClient.top, rcClient.right, rcClient.bottom };
1257 m_pTxtHost->GetTextService()->TxDraw(DVASPECT_CONTENT,
1270 CGdiAlpha::AlphaRestore(ai);
1272 ::SetGraphicsMode(hdc, nOldMode);
1274 rt->ReleaseDC(hdc, &rcClient);
1278 pRT->
AlphaBlend(&rcClient, rt, &rcClient, 255);
1286 __baseCls::OnSetFocus(wndOld);
1291 m_pTxtHost->GetTextService()->OnTxUIActivate();
1292 m_pTxtHost->GetTextService()->TxSendMessage(WM_SETFOCUS, 0, 0, 0);
1294 SetSel((DWORD)MAKELONG(0, -1), TRUE);
1297 if (ES_PASSWORD & m_dwStyle || ES_NUMBER & m_dwStyle)
1305 if (ES_PASSWORD & m_dwStyle || ES_NUMBER & m_dwStyle)
1310 __baseCls::OnKillFocus(wndFocus);
1314 m_pTxtHost->GetTextService()->OnTxUIDeactivate();
1315 m_pTxtHost->GetTextService()->TxSendMessage(WM_KILLFOCUS, 0, 0, 0);
1324 if (idEvent == TIMER_INVALIDATE)
1331 __baseCls::OnTimer(idEvent);
1337 UINT uRet = SC_WANTCHARS | SC_WANTARROWS;
1340 if (m_dwStyle & ES_WANTRETURN)
1341 uRet |= SC_WANTRETURN;
1349 LRESULT lresult = -1;
1355 if (uCode == SB_THUMBPOSITION)
1359 m_pTxtHost->GetTextService()->TxSendMessage(EM_GETSCROLLPOS, 0,
reinterpret_cast<LPARAM
>(&scrollPos), NULL);
1369 m_pTxtHost->GetTextService()->TxSendMessage(EM_SETSCROLLPOS, 0,
reinterpret_cast<LPARAM
>(&scrollPos), NULL);
1370 m_pTxtHost->GetTextService()->TxSendMessage(EM_GETSCROLLPOS, 0,
reinterpret_cast<LPARAM
>(&scrollPos), NULL);
1381 if (lPos != GetScrollPos(bVertical))
1382 SetScrollPos(bVertical, lPos, TRUE);
1386 m_pTxtHost->GetTextService()->TxSendMessage(bVertical ? WM_VSCROLL : WM_HSCROLL, MAKEWPARAM(uCode, nPos), 0, &lresult);
1389 m_pTxtHost->GetTextService()->TxGetVScroll(NULL, NULL, &lPos, NULL, NULL);
1393 m_pTxtHost->GetTextService()->TxGetHScroll(NULL, NULL, &lPos, NULL, NULL);
1396 if (lPos != GetScrollPos(bVertical))
1397 SetScrollPos(bVertical, lPos, TRUE);
1400 m_pTxtHost->GetTextService()->TxSendMessage(bVertical ? WM_VSCROLL : WM_HSCROLL, MAKEWPARAM(uCode, nPos), 0, &lresult);
1404 m_pTxtHost->GetTextService()->TxGetVScroll(NULL, NULL, &lPos, NULL, NULL);
1408 m_pTxtHost->GetTextService()->TxGetHScroll(NULL, NULL, &lPos, NULL, NULL);
1410 if (lPos != GetScrollPos(bVertical))
1411 SetScrollPos(bVertical, lPos, TRUE);
1415 if (uCode == SB_THUMBTRACK)
1417 return lresult == 0;
1424 if (!rcClient.PtInRect(pt))
1428 m_pTxtHost->GetTextService()->OnTxSetCursor(DVASPECT_CONTENT, -1, NULL, NULL, hdc, NULL, &rcClient, pt.x, pt.y);
1435 BOOL bRet = __baseCls::SwndProc(uMsg, wParam, lParam, lResult);
1440 if (uMsg == EM_GETRECT)
1446 if (
m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wParam, lParam, lResult) == S_OK)
1458 GETRENDERFACTORY->CreateRenderTarget(&pRT, 0, 0);
1464 pFont = (
IFontS *)pRT->GetCurrentObject(OT_FONT);
1466 pRT->MeasureText(_T(
"A"), 1, &szTxt);
1469 memset(pcf, 0,
sizeof(CHARFORMAT2W));
1470 pcf->cbSize =
sizeof(CHARFORMAT2W);
1471 pcf->dwMask = CFM_SIZE | CFM_OFFSET | CFM_FACE | CFM_CHARSET | CFM_COLOR | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE;
1474 pcf->crTextColor = pRT->GetTextColor() & 0x00ffffff;
1476 pcf->crTextColor = pRT->GetTextColor();
1478 HDC hdc = GetDC(NULL);
1479 LONG yPixPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
1480 ReleaseDC(NULL, hdc);
1481 const LOGFONT *plf = pFont->
LogFont();
1482 pcf->yHeight = abs(MulDiv(pFont->
TextSize(), LY_PER_INCH, yPixPerInch));
1483 if (SLayoutSize::defUnit != SLayoutSize::px &&
IsRichScale())
1486 pcf->yHeight /= (
GetScale() / 100);
1491 pcf->dwEffects |= CFE_BOLD;
1493 pcf->dwEffects |= CFE_ITALIC;
1495 pcf->dwEffects |= CFE_UNDERLINE;
1496 pcf->bCharSet = plf->lfCharSet;
1497 pcf->bPitchAndFamily = plf->lfPitchAndFamily;
1499 wcscpy(pcf->szFaceName, plf->lfFaceName);
1503 MultiByteToWideChar(CP_ACP, 0, plf->lfFaceName, LF_FACESIZE, pcf->szFaceName, LF_FACESIZE);
1511 memset(ppf, 0,
sizeof(PARAFORMAT2));
1512 ppf->cbSize =
sizeof(PARAFORMAT2);
1513 ppf->dwMask = PFM_ALL;
1515 ppf->rgxTabs[0] = lDefaultTab;
1517 if (m_dwStyle & ES_CENTER)
1518 ppf->wAlignment = PFA_CENTER;
1519 else if (m_dwStyle & ES_RIGHT)
1520 ppf->wAlignment = PFA_RIGHT;
1522 ppf->wAlignment = PFA_LEFT;
1529 EventRENotify evt(
this);
1530 evt.iNotify = iNotify;
1546 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_WORDWRAP, fWordWrap ? TXTBIT_WORDWRAP : 0);
1551 return (m_dwStyle & ES_READONLY) != 0;
1576 m_pfDef.wAlignment = wNewAlign;
1579 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, 0);
1591 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_RICHTEXT, fRich ? TXTBIT_RICHTEXT : 0);
1601 m_pfDef.dxOffset = lNewIndent;
1603 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, 0);
1608 BOOL fResult = fSaveSelection;
1641 m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wParam, lParam, NULL);
1659 point.Offset(rcCantainer.TopLeft());
1661 ::ClientToScreen(hHost, &point);
1663 DWORD dwStart = 0, dwEnd = 0;
1664 SSendMessage(EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
1665 BOOL hasSel = dwStart < dwEnd;
1666 UINT uLen = (UINT)
SSendMessage(WM_GETTEXTLENGTH, 0, 0);
1667 BOOL bReadOnly = m_dwStyle & ES_READONLY;
1668 EnableMenuItem(menu.m_hMenu, MENU_CUT, MF_BYCOMMAND | ((hasSel && (!bReadOnly)) ? 0 : MF_GRAYED));
1669 EnableMenuItem(menu.m_hMenu, MENU_COPY, MF_BYCOMMAND | (hasSel ? 0 : MF_GRAYED));
1670 EnableMenuItem(menu.m_hMenu, MENU_PASTE, MF_BYCOMMAND | ((canPaste && (!bReadOnly)) ? 0 : MF_GRAYED));
1671 EnableMenuItem(menu.m_hMenu, MENU_DEL, MF_BYCOMMAND | ((hasSel && (!bReadOnly)) ? 0 : MF_GRAYED));
1672 EnableMenuItem(menu.m_hMenu, MENU_SELALL, MF_BYCOMMAND | ((uLen > 0) ? 0 : MF_GRAYED));
1674 UINT uCmd = menu.
TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN, point.x, point.y, hHost, NULL,
GetScale());
1676 EventREMenu evt(
this);
1713 EventKeyDown evt(
this);
1714 evt.bCancel = FALSE;
1716 evt.nFlags = nFlags;
1724 if (nChar == VK_RETURN && !(m_dwStyle & ES_WANTRETURN) && !(GetKeyState(VK_CONTROL) & 0x8000))
1732#define CTRL(_ch) (_ch - 'A' + 1)
1742 if (!(GetKeyState(VK_CONTROL) & 0x8000) && !(m_dwStyle & ES_WANTRETURN))
1747 if (!
m_fWantTab && !(GetKeyState(VK_CONTROL) & 0x8000))
1751 if (m_dwStyle & ES_NUMBER && !isdigit(nChar) && nChar !=
'-' && nChar !=
'.' && nChar !=
',')
1753 if ((m_dwStyle & ES_UPPERCASE) && nChar >=
'a' && nChar <=
'z')
1759 if ((m_dwStyle & ES_LOWERCASE) && nChar >=
'A' && nChar <=
'Z')
1769 if (IsDBCSLeadByte(nChar))
1778 m_pTxtHost->GetTextService()->TxSendMessage(WM_IME_CHAR, nChar, 0, NULL);
1790 __baseCls::OnNcCalcSize(bCalcValidRects, lParam);
1796 rcInsetPixel.top = rcInsetPixel.bottom = (m_rcClient.Height() -
m_nFontHeight) / 2;
1799 m_siHoz.nPage = m_rcClient.Width() - rcInsetPixel.left - rcInsetPixel.right;
1800 m_siVer.nPage = m_rcClient.Height() - rcInsetPixel.top - rcInsetPixel.bottom;
1805 LONG xPerInch = ::GetDeviceCaps(hdc, LOGPIXELSX);
1806 LONG yPerInch = ::GetDeviceCaps(hdc, LOGPIXELSY);
1809 m_sizelExtent.cx = DtoHimetric(m_rcClient.Width(), xPerInch);
1810 m_sizelExtent.cy = DtoHimetric(m_rcClient.Height(), yPerInch);
1812 m_rcInset.left = DtoHimetric(rcInsetPixel.left, xPerInch);
1813 m_rcInset.right = DtoHimetric(rcInsetPixel.right, xPerInch);
1814 m_rcInset.top = DtoHimetric(rcInsetPixel.top, yPerInch);
1815 m_rcInset.bottom = DtoHimetric(rcInsetPixel.bottom, yPerInch);
1823 m_pTxtHost->GetTextService()->OnTxUIDeactivate();
1824 m_pTxtHost->GetTextService()->TxSendMessage(WM_KILLFOCUS, 0, 0, NULL);
1827 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_EXTENTCHANGE | TXTBIT_CLIENTRECTCHANGE, TXTBIT_EXTENTCHANGE | TXTBIT_CLIENTRECTCHANGE);
1831 m_pTxtHost->GetTextService()->OnTxUIActivate();
1832 m_pTxtHost->GetTextService()->TxSendMessage(WM_SETFOCUS, 0, 0, NULL);
1840 return SUCCEEDED(
SetAttribute(L
"readonly", wParam ? L
"1" : L
"0"));
1849 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_MAXLENGTHCHANGE, TXTBIT_MAXLENGTHCHANGE);
1855 if (wParam == SCF_DEFAULT && !FValidCF((CHARFORMAT2W *)lParam))
1857 SSLOGI() <<
"set default char format failed! only CHARFORMAT2W can be set for default char format";
1861 m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wParam, lParam, NULL);
1862 if (wParam == SCF_DEFAULT)
1864 m_cfDef = *(CHARFORMAT2W *)lParam;
1865 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_CHARFORMATCHANGE, TXTBIT_CHARFORMATCHANGE);
1872 if (!FValidPF((PARAFORMAT *)lparam))
1880 if (!(wparam & SCF_DEFAULT))
1882 HRESULT hr =
m_pTxtHost->GetTextService()->TxSendMessage(WM_GETTEXTLENGTH, 0, 0, 0);
1886 wparam |= SCF_DEFAULT;
1890 if (wparam & SCF_DEFAULT)
1892 m_pfDef = *(PARAFORMAT2 *)lparam;
1893 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, TXTBIT_PARAFORMATCHANGE);
1897 m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wparam, lparam,
1908 HRESULT hr =
m_pTxtHost->GetTextService()->TxSendMessage(uMsg, wparam, lparam, 0);
1913 ULONG cNewText = (ULONG)(lparam ? _tcslen((LPCTSTR)lparam) : 0);
1928 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_CHARFORMATCHANGE, TXTBIT_CHARFORMATCHANGE);
1955 if (nBufLen < str.GetLength())
1957 else if (nBufLen == str.GetLength())
1958 _tcsncpy(pBuf, str.c_str(), str.GetLength());
1960 _tcscpy(pBuf, str.c_str());
1961 return str.GetLength();
1970 SSendMessage(WM_GETTEXT, (WPARAM)nLen + 1, (LPARAM)pBuf);
1972 return S_CW2T(strRet);
1977 LRESULT lResult = 0;
1980 m_pTxtHost->GetTextService()->TxSendMessage(WM_GETTEXTLENGTH, 0, 0, &lResult);
1982 return (
int)lResult;
1988 SSendMessage(EM_REPLACESEL, (WPARAM)bCanUndo, (LPARAM)pszText);
1997 SSendMessage(EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
2011 m_style.SetTextColor(0, GETCOLOR(strValue));
2019DWORD CALLBACK EditStreamInCallback_FILE(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
2021 FILE *f = (FILE *)dwCookie;
2022 LONG nReaded = (LONG)fread(pbBuff, 1, cb, f);
2028DWORD CALLBACK EditStreamOutCallback_FILE(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
2030 FILE *f = (FILE *)dwCookie;
2031 LONG nWrited = (LONG)fwrite(pbBuff, 1, cb, f);
2043DWORD CALLBACK EditStreamInCallback_MemBlock(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
2045 MemBlock *pmb = (MemBlock *)dwCookie;
2046 if (pmb->nRemains >= cb)
2048 memcpy(pbBuff, pmb->pBuf, cb);
2050 pmb->nRemains -= cb;
2057 memcpy(pbBuff, pmb->pBuf, pmb->nRemains);
2058 pmb->pBuf += pmb->nRemains;
2060 *pcb = pmb->nRemains;
2075 SStringTList lstSrc;
2076 int nSegs = ParseResID(S_CW2T(strValue), lstSrc);
2077 LPCTSTR pszType = NULL;
2078 LPCTSTR pszName = NULL;
2079 if (lstSrc.GetCount() == 2)
2081 pszType = lstSrc[0];
2082 pszName = lstSrc[1];
2086 pszName = lstSrc[0];
2088 size_t dwSize = GETRESPROVIDER->GetRawBufferSize(pszType, pszName);
2092 MemBlock mb = { NULL, 0 };
2094 mb.pBuf = (LPBYTE)mybuf.
Allocate(dwSize);
2095 mb.nRemains = (DWORD)dwSize;
2096 GETRESPROVIDER->GetRawBuffer(pszType, pszName, mybuf, dwSize);
2097 es.dwCookie = (DWORD_PTR)&mb;
2098 es.pfnCallback = EditStreamInCallback_MemBlock;
2107 COLORREF crOld =
m_cfDef.crTextColor;
2109 m_cfDef.crTextColor = cr & 0x00ffffff;
2113 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_CHARFORMATCHANGE, TXTBIT_CHARFORMATCHANGE);
2121 SRicheditDropTarget *pDropTarget =
new SRicheditDropTarget(
m_pTxtHost->GetTextService());
2123 pDropTarget->Release();
2134 m_dwStyle |= ES_CENTER;
2136 m_dwStyle |= ES_RIGHT;
2138 m_dwStyle |= ES_LEFT;
2141 if (m_dwStyle & ES_CENTER)
2142 m_pfDef.wAlignment = PFA_CENTER;
2143 else if (m_dwStyle & ES_RIGHT)
2144 m_pfDef.wAlignment = PFA_RIGHT;
2146 m_pfDef.wAlignment = PFA_LEFT;
2147 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(TXTBIT_PARAFORMATCHANGE, 0);
2149 return bLoading ? S_FALSE : S_OK;
2159 lEvtMask |= ENM_CHANGE;
2161 lEvtMask &= ~ENM_CHANGE;
2169 FILE *f = _tfopen(pszFileName, _T(
"wb"));
2173 es.dwCookie = (DWORD_PTR)f;
2174 es.pfnCallback = EditStreamOutCallback_FILE;
2175 DWORD dwRet = (DWORD)
SSendMessage(EM_STREAMOUT, SF_RTF, (LPARAM)&es);
2182 FILE *f = _tfopen(pszFileName, _T(
"rb"));
2186 es.dwCookie = (DWORD_PTR)f;
2187 es.pfnCallback = EditStreamInCallback_FILE;
2188 DWORD dwRet = (DWORD)
SSendMessage(EM_STREAMIN, SF_RTF, (LPARAM)&es);
2195 __baseCls::OnScaleChanged(nScale);
2208 __baseCls::OnRebuildFont();
2214 __baseCls::OnEnable(bEnable, nStatus);
2219 if (CR_INVALID == cr)
2227 if (CR_INVALID != cr)
2233 if (!(m_dwStyle & ES_MULTILINE))
2240 LRESULT lResult = 0;
2254 BOOL bValue = STRINGASBOOL(strValue);
2257 m_dwStyle &= ~dwStyle;
2259 m_dwStyle |= dwStyle, dwBit = txtBit;
2260 if (!bLoading && txtBit != 0)
2262 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(txtBit, dwBit);
2264 return bLoading ? S_FALSE : S_OK;
2269 BOOL bValue = STRINGASBOOL(strValue);
2271 m_dwStyle &= ~dwStyle;
2273 m_dwStyle |= dwStyle;
2274 if (!bLoading && txtBit != 0)
2276 m_pTxtHost->GetTextService()->OnTxPropertyBitsChange(txtBit, txtBit);
2278 return bLoading ? S_FALSE : S_OK;
2283 SStringT strValueT = S_CW2T(strValue);
2285 return bLoading ? S_FALSE : S_OK;
2306 SMap<UINT, SAutoRefPtr<ITimer>>::CPair *p =
m_mapTimer.Lookup(idTimer);
2309 p->m_value->KillTimer();
2310 p->m_value->StartTimer(uTimeout, TRUE, idTimer);
2329 EventTimer *e2 = sobj_cast<EventTimer>(e);
2330 m_pTxtHost->GetTextService()->TxSendMessage(WM_TIMER, e2->uData, 0, NULL);
Header file for the SAutoBuf class, a smart buffer management class.
SXmlNode GetEditCtxMenuTemplate() const
Get the edit context menu template XML node.
A smart buffer management class that automatically handles memory allocation and deallocation.
char * Allocate(size_t nElements)
Allocates a buffer of the specified size. If a buffer is already allocated, it will be freed first.
Smart pointer class for managing COM-style reference-counted objects.
The SMatrix class holds a 3x3 matrix for transforming coordinates. SMatrix does not have a constructo...
BOOL isIdentity() SCONST OVERRIDE
Checks if the matrix is the identity matrix.
virtual CRect GetClientRect() const
Gets the client rectangle.
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handles scroll events.
CRect GetScrollBarRect(BOOL bVert) SCONST OVERRIDE
Gets the rectangle of a scrollbar.
void ScrollUpdate()
Updates the scrollbar.
UINT m_fSingleLineVCenter
HRESULT OnAttrTextColor(const SStringW &strValue, BOOL bLoading)
Set text color attribute.
BOOL SetSaveSelection(BOOL fSaveSelection) OVERRIDE
Set the save selection flag.
LRESULT OnSetParaFormat(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set paragraph format message.
void SetWordWrap(BOOL fWordWrap) OVERRIDE
Set the word wrap setting.
void SetWindowText(LPCTSTR lpszText) OVERRIDE
Set the window text.
BOOL OnTxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw)
Handle set scroll position message.
void SetDefaultAlign(WORD wNewAlign) OVERRIDE
Set the default text alignment.
BOOL SwndProc(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) OVERRIDE
Process window messages.
UINT m_fEnableAutoWordSel
HRESULT OnAttrReStyle2(const SStringW &strValue, DWORD dwStyle, DWORD txtBit, BOOL bLoading)
Handle the restyle attribute (variant)
void OnRButtonDown(UINT nFlags, CPoint point)
Handle right button down message.
void OnTxKillTimer(UINT idTimer)
Handle kill timer message.
void OnTimer(char idEvent)
Handle timer message.
LRESULT OnButtonClick(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle button click message.
void SetDefaultLeftIndent(LONG lNewIndent) OVERRIDE
Set the default left indent.
LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
Handle non-client calculate size message.
HRESULT OnAttrNotifyChange(const SStringW &strValue, BOOL bLoading)
Handle the notify change attribute.
void OnDestroy()
Handle destruction of the control.
virtual void OnScaleChanged(int nScale)
Handle scale change message.
LRESULT OnSetCharFormat(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set character format message.
BOOL SetLimitText(int nLength) OVERRIDE
Set the maximum text length.
virtual HRESULT SetAttribute(const SNS::SStringW &amp;amp;amp;strAttribName, const SNS::SStringW &amp;amp;amp;strValue, BOOL bLoading=FALSE)
Begin the attribute map for the SRichEdit class.
virtual HRESULT OnTxNotify(DWORD iNotify, LPVOID pv)
Handle text notification.
virtual UINT WINAPI OnGetDlgCode() const
Get dialog code.
BOOL OnTimeout(IEvtArgs *e)
Handle timer timeout message.
HRESULT InitDefaultCharFormat(CHARFORMAT2W *pcf, IFontS *pFont=NULL)
Initialize default character format.
virtual void OnRebuildFont()
Handle rebuild font message.
void OnSetFont(IFontS *font, BOOL bRedraw)
Handle set font message.
void OnLButtonUp(UINT nFlags, CPoint point)
Handle left button up message.
LONG GetDefaultLeftIndent() SCONST OVERRIDE
Get the default left indent.
HRESULT InitDefaultParaFormat(PARAFORMAT2 *ppf)
Initialize default paragraph format.
DWORD SaveRtf(LPCTSTR pszFileName) OVERRIDE
Save content to an RTF file.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handle mouse wheel message.
void ReplaceSel(LPCTSTR pszText, BOOL bCanUndo=TRUE) OVERRIDE
Replace the selected text.
BOOL OnTxSetTimer(UINT idTimer, UINT uTimeout)
Handle set timer message.
int OnCreate(LPVOID lpCreateStruct)
Handle creation of the control.
LRESULT OnSetLimitText(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set limit text message.
void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle character message.
LRESULT OnSetText(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set text message.
COLORREF SetDefaultTextColor(COLORREF cr) OVERRIDE
Set the default text color.
void OnLButtonDown(UINT nFlags, CPoint point)
Handle left button down message.
void OnSetFocus(SWND wndOld)
Handle set focus message.
BOOL GetReadOnly() SCONST OVERRIDE
Check if the control is read-only.
virtual BOOL OnSetCursor(const CPoint &pt)
Handle set cursor message.
BOOL IsRichScale() const
Check if rich text scaling is enabled.
HRESULT OnAttrReStyle(const SStringW &strValue, DWORD dwStyle, DWORD txtBit, BOOL bLoading)
Handle the restyle attribute.
void OnEnableDragDrop(BOOL bEnable)
Enable or disable drag-and-drop.
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handle scroll message.
void SetRichTextFlag(BOOL fRich) OVERRIDE
Set the rich text flag.
void SetSel(long nStartChar, long nEndChar, BOOL bNoScroll) OVERRIDE
Set the selection range.
BOOL SetReadOnly(BOOL bReadOnly) OVERRIDE
Set the read-only state.
WORD GetDefaultAlign() SCONST OVERRIDE
Get the default text alignment.
BOOL GetRichTextFlag() SCONST OVERRIDE
Get the rich text flag.
int GetWindowTextLength() const
Get the length of the window text.
void OnEnable(BOOL bEnable, UINT nStatus)
Handle enable message.
LONG GetLimitText() SCONST OVERRIDE
Get the maximum text length.
BOOL GetWordWrap() SCONST OVERRIDE
Get the word wrap setting.
void OnPaint(IRenderTarget *pRT)
Handle paint message.
HRESULT OnAttrEnableDragdrop(const SStringW &strValue, BOOL bLoading)
Handle the enable dragdrop attribute.
DWORD LoadRtf(LPCTSTR pszFileName) OVERRIDE
Load content from an RTF file.
LRESULT OnGetRect(UINT uMsg, WPARAM wp, LPARAM lp)
Handle get rectangle message.
HRESULT OnAttrRTF(const SStringW &strValue, BOOL bLoading)
Set RTF attribute.
void OnKillFocus(SWND wndFocus)
Handle kill focus message.
BOOL CreateCaret(HBITMAP pBmp, int nWid, int nHeight) OVERRIDE
Create a caret.
HRESULT OnAttrAlign(const SStringW &strValue, BOOL bLoading)
Set alignment attribute.
SMap< UINT, SAutoRefPtr< ITimer > > m_mapTimer
void OnMouseMove(UINT nFlags, CPoint point)
Handle mouse move message.
HRESULT OnAttrPasswordChar(const SStringW &strValue, BOOL bLoading)
Handle the password character attribute.
int GetWindowText(TCHAR *pBuf, int nBufLen, BOOL bRawText) OVERRIDE
Get the window text.
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle key down message.
LRESULT OnSetReadOnly(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle set read-only message.
static SApplication * getSingletonPtr(void)
A class representing an ASCII string.
int CompareNoCase(const wchar_t *psz) SCONST
Compares the string with another string, ignoring case.
void ReleaseBuffer(int nNewLength=-1)
Releases the buffer and sets the new length of the string.
const wchar_t * c_str() SCONST
Retrieves a C-style string representation of the string.
wchar_t * GetBufferSetLength(int nNewLength)
Retrieves a modifiable buffer for the string and sets the new length.
virtual void TxImmReleaseContext(HIMC himc)
virtual HRESULT TxGetAcceleratorPos(LONG *pcp)
Get the accelerator character.
virtual void TxSetFocus()
Set the focus to the text window.
virtual HRESULT TxGetViewInset(LPRECT prc)
Get the view rectangle relative to the inset.
virtual HDC TxGetDC()
Get the DC for the host.
virtual HRESULT TxActivate(LONG *plOldState)
Request host to activate text services.
virtual HRESULT OnTxCharFormatChange(const CHARFORMATW *pcf)
Notify host that default character format has changed.
virtual HRESULT OnTxParaFormatChange(const PARAFORMAT *ppf)
Notify host that default paragraph format has changed.
virtual void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll)
Scroll the content of the specified window's client area.
virtual void TxKillTimer(UINT idTimer)
Destroy a timer.
virtual COLORREF TxGetSysColor(int nIndex)
Get the background color for the window.
virtual BOOL TxScreenToClient(LPPOINT lppt)
Converts screen coordinates of a specified point to the client coordinates.
virtual HRESULT TxGetClientRect(LPRECT prc)
Retrieves the coordinates of a window's client area.
virtual BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight)
Create the caret.
virtual HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits)
Bulk access to bit properties.
virtual void TxViewChange(BOOL fUpdate)
Send a WM_PAINT to the window.
virtual BOOL TxSetCaretPos(INT x, INT y)
Set the caret position.
virtual HRESULT TxGetCharFormat(const CHARFORMATW **ppCF)
Get the default character format for the text.
virtual BOOL TxClientToScreen(LPPOINT lppt)
Converts the client coordinates of a specified point to screen coordinates.
virtual BOOL TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw)
Set the scroll range.
virtual void TxSetCapture(BOOL fCapture)
Get mouse capture.
virtual BOOL TxSetTimer(UINT idTimer, UINT uTimeout)
Create a timer with the specified timeout.
virtual BOOL TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags)
Enable the scroll bar.
virtual BOOL TxShowScrollBar(INT fnBar, BOOL fShow)
Show the scroll bar.
virtual void TxInvalidateRect(LPCRECT prc, BOOL fMode)
InvalidateRect.
virtual HRESULT TxDeactivate(LONG lNewState)
Request host to deactivate text services.
virtual BOOL TxShowCaret(BOOL fShow)
Show the caret.
BOOL Init(SRichEdit *pRichEdit)
初始化函数
virtual INT TxReleaseDC(HDC hdc)
Release the DC gotten from the host.
virtual void TxSetCursor(HCURSOR hcur, BOOL fText)
Establish a new cursor shape.
virtual HRESULT TxGetParaFormat(const PARAFORMAT **ppPF)
Get the default paragraph format for the text.
virtual HIMC TxImmGetContext()
virtual HRESULT TxNotify(DWORD iNotify, void *pv)
Notify host of events.
virtual HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle)
Get the background (either opaque or transparent)
ITextServices * GetTextService()
Describe.
virtual HRESULT TxGetScrollBars(DWORD *pdwScrollBar)
Get the bits representing requested scroll bars for the window.
virtual BOOL TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw)
Set the scroll position.
virtual HRESULT TxGetMaxLength(DWORD *plength)
Get the maximum length for the text.
virtual HRESULT TxGetExtent(LPSIZEL lpExtent)
Get the native size.
virtual HRESULT TxGetPasswordChar(TCHAR *pch)
Get the character to display for password input.
virtual HRESULT TxGetSelectionBarWidth(LONG *plSelBarWidth)
Returns HIMETRIC size of the control bar.
HRESULT CreateTextServices(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk)
PCreateTextServices m_funCreateTextServices
~STextServiceHelper()
析构函数
BOOL StartTimer(int nElapse, BOOL bRepeat, LPARAM uData=0) OVERRIDE
启动定时器
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
SAutoRefPtr< ISkinObj > m_pNcSkin
int GetWindowText(TCHAR *pBuf, int nBufLen, BOOL bRawText) OVERRIDE
Retrieves the window text.
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
BOOL IsFocused() SCONST OVERRIDE
Checks if the window has focus.
PSWNDMSG GetCurMsg(void) const
Retrieves the current message being processed.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the mouse wheel event.
LRESULT SSendMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0, BOOL *pbMsgHandled=NULL) OVERRIDE
Sends a message to the window.
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
SWND SetCapture() OVERRIDE
Sets the window to capture the mouse.
void SetFocus() OVERRIDE
Sets the focus to the window.
BOOL IsDisabled(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is disabled.
void KillFocus() OVERRIDE
Kills the focus from the window.
BOOL KillTimer(char id) OVERRIDE
Kills a timer for the window.
SAutoRefPtr< ISkinObj > m_pBgSkin
BOOL FireCtxMenu(POINT pt) OVERRIDE
Fires a context menu event.
void Invalidate() OVERRIDE
Invalidates the entire window.
BOOL CreateCaret(HBITMAP pBmp, int nWid, int nHeight) OVERRIDE
Creates a caret.
void SetMsgHandled(BOOL bHandled)
Sets the message handled flag.
const SwndStyle & GetStyle() const
Retrieves the style of the window.
HWND GetHostHwnd() OVERRIDE
Retrieves the host window handle.
SWND m_swnd
Member variables representing various properties of the window.
void BeforePaintEx(IRenderTarget *pRT)
Prepares the drawing environment for the current window's RenderTarget, starting from the top-level w...
BOOL ReleaseCapture() OVERRIDE
Releases the mouse capture from the window.
Class representing an XML node.
CRect GetPadding() const
Retrieves the padding rectangle.
long Release() override
Decrements the reference count and deletes the object if the count reaches zero.
BOOL IsBold() SCONST PURE
Checks if the font is bold.
int TextSize() SCONST PURE
Retrieves the text size of the font.
BOOL IsItalic() SCONST PURE
Checks if the font is italic.
BOOL IsUnderline() SCONST PURE
Checks if the font has an underline.
const LOGFONT * LogFont() SCONST PURE
Retrieves the LOGFONT structure of the font.
Interface for rendering target objects.
HRESULT AlphaBlend(LPCRECT pRcDest, IRenderTarget *pRTSrc, LPCRECT pRcSrc, BYTE byAlpha) PURE
Performs an alpha-blended transfer from one render target to another.
HRESULT GetTransform(float matrix[9]) SCONST PURE
Retrieves the current coordinate transformation matrix.
BOOL IsOffscreen() SCONST PURE
Check if the render target is offscreen.
HRESULT PushClipRect(LPCRECT pRect, UINT mode=RGN_AND) PURE
Push a rectangular clip region.
HRESULT PopClip() PURE
Pop the last clip region from the stack.
BOOL RegisterDragDrop(SWND swnd, IDropTarget *pDropTarget) PURE
Registers an IDropTarget with a Swnd.
HWND GetHostHwnd() PURE
Retrieves the handle to the host window.
void GetContainerRect(RECT *ret) SCONST PURE
Retrieves the container's display rectangle.
void OnUpdateCursor() PURE
Updates the cursor.
void EnableIME(BOOL bEnable) PURE
Enables or disables the input method editor (IME).
BOOL UnregisterDragDrop(SWND swnd) PURE
Unregisters an IDropTarget from a Swnd.
Structure representing a window message.